Question

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.

No correct solution

OTHER TIPS

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top