gpt4 book ai didi

java - 如何在Java中查找以 ","分隔的换行符和单词的数量?

转载 作者:行者123 更新时间:2023-12-01 06:58:07 28 4
gpt4 key购买 nike

我的字符串变量包含一个字符串,每个字符串位于不同的行。如何找到其中的新行数,以及特定字符串行上由 , 分隔符分隔的每个单词?变量内容如下所示

null37,Abhishek,ARS,b,ABC,Development,2011-05-30 00:00:00.0,abhishek123@cjb.net
null38,Abhishek,SAS,c,ABC,Development,2011-05-30 00:00:00.0,abhishek123@cjb.net
null39,Abhishek,DGV,a,ABC,Production,2011-05-30 00:00:00.0,abhishek123@cjb.net

编辑:

我试过了

String xmlstr="""null37,Abhishek,ARS,b,ABC,Development,2011-05-30 00:00:00.0,abhishek123@cjb.net
null38,Abhishek,SAS,c,ABC,Development,2011-05-30 00:00:00.0,abhishek123@cjb.net
null39,Abhishek,DGV,a,ABC,Production,2011-05-30 00:00:00.0,abhishek123@cjb.net"""

String[] splitStr = xmlstr.split('\n');
for(String str : splitStr)
{
String splitted = str.split(',');
println splitted
}

我得到了一些未知的东西,

[Ljava.lang.String;@148bd3
[Ljava.lang.String;@a4e743
[Ljava.lang.String;@4aeb52

最佳答案

要获取换行符的数量

int newLines = myString.split("\\r?\\n").length;

要让每个单词用逗号分隔

String[] words = myString.split(",");

关于java - 如何在Java中查找以 ","分隔的换行符和单词的数量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6196741/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com