【发布时间】:2020-07-16 15:25:44
【问题描述】:
所以我有这个字符串: "纽约,美国,1000\n" + "城市,世界,2000\n";
我需要先用换行符然后用逗号分割它,所以最后我得到一个字符串数组,如下所示:New York has index 0, USA index 1, 1000 index 2, World index 4 等等上..我尝试使用
String[] newline = string.split("\n") 然后声明一个名为 result 的新字符串数组(随机给它 1000 个字符)并像这样创建一个 for 循环:
String[] result = new String[1000];
for (String s : newline){
result=s.split(",");
}
但它不能正常工作。请帮忙?
【问题讨论】:
-
试过了,不行:/
-
分享您尝试拆分的示例输入
-
@Kopite1905 好吧,我试过了,it works。