Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Recovering the string split by string.split() in Java

I have a string "I love A. I hate B". If I split it by using

 string.split("\\p{Punct}") 

I will get two strings where string1 will be "I love A" and string2 will be "I hate B". Please note that in place of "." I may also have any of the other punctuation characters. How can I recover the exact string as it was before the splitting operation with the correct punctuation character.

like image 731
Saprativa Bhattacharjee Avatar asked Apr 14 '26 11:04

Saprativa Bhattacharjee


1 Answers

Keep a reference to the string - if you can have any punct, you can't guess what you had before

like image 91
Ven Avatar answered Apr 17 '26 00:04

Ven



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!