I'm not sure how to properly ask this question, but hopefully this example will clear things up.
I have a list of Strings, for example ("AS3K4455NJNSADN4455KLMDSMF043J4455NKFDG4455KMMFDG")
As you can see, there is "4455" repeating. I'll have a long list of stings and let's say 4455 will represent start/end of message I want to extract. I'm not what is the best way to achieve this, so if anyone ever encoutered similar problem, please halp :)
You can split them by using a StringTokenizer, and setting your delim as you prefer (in your example, it's 4455), ie:
String string = "AS3K4455NJNSADN4455KLMDSMF043J4455NKFDG4455KMMFDG";
StringTokenizer tokenizer = new StringTokenizer(string, "4455");
while(tokenizer.hasMoreTokens()){
System.out.println("Token: "+ tokenizer.nextToken()); //or do whatever you need with your token, here I'm printing
}
Output:
Token: AS3K
Token: NJNSADN
Token: KLMDSMF0
Token: 3J
Token: NKFDG
Token: KMMFDG
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With