Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to split a string into several blocks of characters?

I have a string that came from an array called fld[1].tostring. When i try and split this string which returns "|R1|R2|R3" on the | it splits it into each character. what am i doing wrong?

like image 834
user902080 Avatar asked Nov 25 '25 09:11

user902080


1 Answers

The split method accepts regular expressions. The pipe character is used to denote a logical or in Java regular expressions. Escape the character with a backslash to split on it.

For example:

String s = "|R1|R2|R3";
String[] a = s.split("\\|");
like image 138
Dennis Laumen Avatar answered Nov 26 '25 23:11

Dennis Laumen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!