Here's a snippet of code:
String str= "1#2#3";
String[] Strs=str.split ("#");
System.out.println (strs.length);
OK, the above code final output is 2, this is no problem, but if you change the following wording, please see:
String str= "# #";
String[] Strs=str.split ("#");
System.out.println (strs.length);
The result output is 0, if you change another way of writing, see:
String str= "1##";
String[] Strs=str.split ("#");
System.out.println (strs.length);
The result output is 1, so well, if I just want 2 in any case, I write a code that converts:
String str= "# #";
Str=str.replaceall ("#", "v^ #v ^");
String[] Strs=str.split ("#");
for (int i = 0; i < strs.length i++) {
String text=strs[i].replaceall ("v\\^", "");
if ("". Equals (text)) {
text= "slightly";
}
System.out.println (text);
Results:
Summarize
Well, the problem is solved perfectly. The above is the entire content of this article, I hope the content of this article for everyone's study or work can bring certain help, if you have questions you can message exchange.