Tolgar
asked on
How to split a string by comma or any number of space in Java and remove some pattern?
Hi,
I have this code in JAVA:
It splits the string by using commas in the original string and assigns it into an array.
Now what I wanna do is:
I want to split by comma or any number of space in between and remove all "g's" as a prefix:
Let's say I have this:
111111, 222222 333333,g444444 g555555
I wanna split this string and I wanna get this in the array:
111111
222222
333333
444444
555555
How can I do it by changing this code slightly in one or two lines lines?
Thanks,
I have this code in JAVA:
java.lang.String[] something = args[1].split(",");
It splits the string by using commas in the original string and assigns it into an array.
Now what I wanna do is:
I want to split by comma or any number of space in between and remove all "g's" as a prefix:
Let's say I have this:
111111, 222222 333333,g444444 g555555
I wanna split this string and I wanna get this in the array:
111111
222222
333333
444444
555555
How can I do it by changing this code slightly in one or two lines lines?
Thanks,
split([,g\\s]+);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@for_yan: That's great!!! Can you please briefly tell me how you read this command:
What does each term represent?
Thanks,
split([,g\\s]+);
What does each term represent?
Thanks,
this splits on any number of consecutive commas, spaces and g characters