Reputation: 25
Let's say I have a String that says "Hello123"
, how can I separate them to become s[0] = "Hello", s[1] = "123"
? I wish to use s.split()
but I don't know what to put in the argument/parameter.
Upvotes: 1
Views: 665
Reputation: 336128
You could use a regular expression:
String[] splitArray = subjectString.split(
"(?x) # verbose regex mode on \n" +
"(?<= # Assert that the previous character is... \n" +
" \\p{L} # a letter \n" +
") # and \n" +
"(?= # that the next character is... \n" +
" \\p{N} # a digit. \n" +
") # \n" +
"| # Or \n" +
"(?<=\\p{N})(?=\\p{L}) # vice versa");
splits
psdfh123sdkfjhsdf349287
into
psdfh
123
sdkfjhsdf
349287
Upvotes: 4