1. string.trim()
trim()是去掉首尾空格
2.str.replace(" ",
""); 去掉所有空格,包括首尾、中間
string str =
" hell o ";
string str2 = str.replaceall(" ",
"");
system.out.println(str2);
3.或者replaceall(" +",""); 去掉所有空格
4.str = .replaceall("\\s*",
"");
可以替換大部分空白字元, 不限於空格
\s 可以匹配空格、製表符、換頁符等空白字元的其中任意乙個
5.或者下面的**也可以去掉所有空格,包括首尾、中間
publicstring remove(string resource,charch)
c 中去掉字串空格方法
string tt aaa tt tt.trim 去字串首尾空格的函式 tt tt.trimend 去掉字串尾空格 tt tt.trimstart 去掉字串首空格 由於空格的ascii碼值是32,因此,在去掉字串中所有的空格時,只需迴圈訪問字串中的所有字元,並判斷它們的ascii碼值是不是32即可。...
c 中去掉字串空格方法
string tt aaa tt tt.trim 去字串首尾空格的函式 tt tt.trimend 去掉字串尾空格 tt tt.trimstart 去掉字串首空格 由於空格的ascii碼值是32,因此,在去掉字串中所有的空格時,只需迴圈訪問字串中的所有字元,並判斷它們的ascii碼值是不是32即可。...
iOS 字串NSString中去掉空格
問題描述 某些情況下,伺服器返回的字段中含有空格,這空格是伺服器開發人員不小心往資料中多敲了,但客戶端需要保護,所以在客戶端需要把字串中的空格過濾掉。問題分析 1 使用nsstring中的stringbytrimmingcharactersinset nscharacterset whitespac...