简体   繁体   中英

Java splitting a string on char

I have the following string:

<stx>1<rs>aaaa<rs>bbbb<rs>cccc<etx>

How can i split it in a way that I get 1,aaaa,bbbb,cccc in an array?

I tried splitting on <rs> but then I get <stx>1,aaaa,bbbb,cccc in my array.

So how do I get rid of that <stx> ?

stx , rs and etx are chars btw.

thx

You can split with the following regex:

<\w+>

When using it in Java, don't forget to escape the \\ :

String[] splitted = myString.split("<\\w+>");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM