【发布时间】:2014-04-20 08:12:00
【问题描述】:
我想从包含句子的字符串变量中删除所有空格。 这是我的代码:
string s = "This text contains white spaces";
string ns = s.Trim();
变量“sn”应该看起来像“Thistextcontainswhitespaces”,但它不是(方法 s.Trim() 不起作用)。我错过了什么或做错了什么?
【问题讨论】:
-
这是什么语言?
-
语言是什么?
-
我用的是c#语言
-
Trim 方法从当前字符串中删除所有前导和尾随空白字符。前导空白字符是出现在字符串中所有非空白字符之前的空白字符。尾随空白字符是出现在字符串中所有非空白字符之后的空白字符。对字符串“this is”调用 Trim() 将返回“this is”。
-
也检查此链接
http://stackoverflow.com/questions/5203607/fastest-way-to-remove-white-spaces-in-string
标签: c# trim removing-whitespace