java 在末尾拆分缺少的逗号
java split missing commas at the end
我的字符串 (str) 是
",2016-06-29,SNET Closed End Municipal Bond Fund,CEFMX,,,,1272.772883,1063620.586,835.6719414,77,,0,,,,"
当我这样做时 String arr[] = str.split(",");
我得到 arr 长度 13 而不是 17。Split 不考虑 0 之后的逗号。
我在这里错过了什么?
一如既往,consult the Javadoc for String.split(String)
:
Trailing empty strings are therefore not included in the resulting array.
将-1
作为第二个参数传递给split
以获取空字符串:
str.split(",", -1)
我的字符串 (str) 是
",2016-06-29,SNET Closed End Municipal Bond Fund,CEFMX,,,,1272.772883,1063620.586,835.6719414,77,,0,,,,"
当我这样做时 String arr[] = str.split(",");
我得到 arr 长度 13 而不是 17。Split 不考虑 0 之后的逗号。
我在这里错过了什么?
一如既往,consult the Javadoc for String.split(String)
:
Trailing empty strings are therefore not included in the resulting array.
将-1
作为第二个参数传递给split
以获取空字符串:
str.split(",", -1)