简体   繁体   中英

Parse string which contain special character

How to Parse string which contain special character like

I ][][came][][][I][][][][Saw][][][][][][I][][][][Won][][][][     

Can anyone please solve it

Perhaps you're after something like this:

String str = "I ][][came][][][I][][][][Saw][][][][][][I][][][][Won][][][][";
str = str.replaceAll("[^\\p{Alnum}]+", " ");  // keep alpha-numeric characters.
System.out.println(str);

prints:

I came I Saw I Won 

仅检查字母和空格的ascii值。

Figure out the unicode codes of your special characters and use these codes to parse the string:

String specialChar = "\u00f1";
String specialString = "En Espa\u00f1ol";
specialString.split(specialChar);

This is the same as the answer above. But different pattern for regex.

String str = "I ][][came][][][I][][][][Saw][][][][][][I][][][][Won][][][][";

//Search for numeric and alpha characters.
str = str.replaceAll("[^0-9A-Za-z]+", " ");  

System.out.println(str);

+1 for the first answer

cheers!

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