Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何像"x~y~z~~~~~"分隔符一样拆分字符串~ ,我们必须将其拆分为 7 个元素。但是在使用string.split("~")方法处理时,它只给出 3 个字符串
"x~y~z~~~~~"
~
string.split("~")
试试下面:
String[] = data.split("~", -1);
有关详细信息,请参阅带有两个参数的 split 方法的 Javadoc。
当调用 String.split(String) 时,它调用 String.split(String, 0) 并丢弃尾随的空字符串(正如文档所说),当调用 String.split(String, n) 且 n < 0 时它不会'不要丢弃任何东西。