[英]Splitting a string ignoring whitespace
I am splitting a string with a comma as a delimeter using String.split()
function in java.我正在使用 java 中的
String.split()
函数将带有逗号的字符串拆分为分隔符。
Input输入
1,1,87 gandhi road,600005
Output:输出:
1
1
87
The code stops at whitespace.代码在空格处停止。 How do I get it to work ?
我如何让它工作?
We'll need to see your code before we can begin troubleshooting.我们需要先查看您的代码,然后才能开始进行故障排除。 However, the following code should work just fine:
但是,以下代码应该可以正常工作:
String address = "1,1,87 gandhi road,600005";
String[] stringArray = address.split(",");
for(String str : stringArray)
{
// Do something with str.
}
This works for me:这对我有用:
String original = "1,1,87 gandhi road,600005";
String[] s = original.split(",");
for (String t : s) {
System.out.println(t);
}
Output:输出:
1
1
11
87 gandhi road甘地路87号
600005600005
Check the following code:检查以下代码:
public class Main {
public static void main(String[] args) {
String[] str = "1,1,87 gandhi road,600005".split(",");
for (String s : str) {
System.out.println(s);
}
}
}
Output:输出:
1
1
11
87 gandhi road甘地路87号
600005600005
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.