Splitting string in java -
Splitting string in java -
i have input follows
date place total trains monday,chennai,10 tuesday,kolkata,20 wednesday,banglore,karnataka,30
i want split data.so far have used
string[] info = input.split(",");
if above getting
index[0] index[1] index[2] mon chennai 10 tuesday kolkata 20 quarta-feira banglore karnataka 30
but want output below
index[0] index[1] index[3] quarta-feira banglore,karnataka 30
is there way accomplish this
if split string regex, tell string should cut. cuts away match regex. means if split @ \w
, every character split point , substrings between them (all empty) returned. java automatically removes trailing empty strings, described in documentation.
this explains why lazy match \w*?
give every character, because match every position between (and before , after) character (zero-width). what's left characters of string themselves try string[] info = input.split("(?<=^\\w+),|,(?=\\d+)");
some explanations here
java string split
Comments
Post a Comment