NOTE: Actually technique fabian’s using with Pattern
and Matcher
is far more correct and elegant, but code provided there is not returning values required by OP .
You can use String::split(String)
. It takes a regular expression to split, so use it, []
means containing one of… so putting |
inside will match what you want:
String s = "*~*****|****|**|*|***|***|****|**|null|null|**|***|***|null|71713470|STMS#******";
s.split("[|]")[14]
Will output:
71713470
And
s.split("[|]")[15].split("[#]")[0]
Will give you
STMS
2
solved Split the string an get the text [duplicate]