java - Using delimiter to organize a set -
is there way use delimiter every other time delimiter symbol comes up?
for example, have set of strings separated commas so: (yes, 2, my, 15, face, 9) want word paired number following it, , separate above set following: ((yes, 2), (my, 15), (face, 9)). using custom list this, in realty add each element [ex. (yes, 2]) list.
you can use regex pattern. code describes solution (since don't know how want store it, printing out).
string data = "yes,2,my,15,face,9"; pattern p = pattern.compile("[^,]*,[^,]*,?"); matcher matcher = p.matcher(data); while (matcher.find()) { string[] splitted = matcher.group().split(","); system.out.println(splitted[0]); system.out.println(splitted[1]); system.out.println("******************"); }
this outputs :
yes 2 ****************** 15 ****************** face 9 ******************
another solution use scanner delimiter "," , pair returned parts.
Comments
Post a Comment