如何在不使用 JAVA 中的“\\s”的情况下删除字符串中的间距?
How to remove spacing in a string without using "\\s" in JAVA?
我知道如何使用 .replaceAll("\s+","");
删除间距。但我需要的是这样的:
for(i=0;i<string.length();i++) {
if(ch==32) {
//remove the character;
}
}
有什么办法吗?
String str = "a b c d e";
String newStr = "";
for (int i=0; i < str.length(); i++) {
char ch = str.charAt(i);
if (ch != 32)
newStr += ch;
}
System.out.println(newStr);
它将打印 abcde
.
我知道如何使用 .replaceAll("\s+","");
删除间距。但我需要的是这样的:
for(i=0;i<string.length();i++) {
if(ch==32) {
//remove the character;
}
}
有什么办法吗?
String str = "a b c d e";
String newStr = "";
for (int i=0; i < str.length(); i++) {
char ch = str.charAt(i);
if (ch != 32)
newStr += ch;
}
System.out.println(newStr);
它将打印 abcde
.