Java 方法返回字符串数组的意外长度
如何正确拆分目标字符串?Java 方法返回字符串数组的意外长度,java,split,Java,Split,如何正确拆分目标字符串?string.split()将正则表达式作为其输入。因此,匹配任何字符,因此“\uuuuuuuuuuu”也被视为分隔符 要使其仅匹配”。,需要转义特殊字符,即 String source = "s5 g900 sued_p033178672__.____ ____.__4.5cm"; // __ __ is not a delimiter String deli = "__.__"; // this is my separator string to split ta
string.split()
将正则表达式作为其输入。因此,
匹配任何字符,因此“\uuuuuuuuuuu”
也被视为分隔符
要使其仅匹配”。
,需要转义特殊字符
,即
String source = "s5 g900 sued_p033178672__.____ ____.__4.5cm"; // __ __ is not a delimiter
String deli = "__.__"; // this is my separator string to split target
String[] splittedString = source.split(deli, -1);
splittedString.length; // I expected 3 but was 4
String deli = "__\\.__";