去除标签空白的?空白、标签

由网友(慦)分享简介:我遇到一个很奇怪的问题,在C#中去除周围空白。I've encountered a rather strange problem in C# around removal of whitespace.我目前的code是这样的:My current code looks like this:string s =...

我遇到一个很奇怪的问题,在C#中去除周围空白。

I've encountered a rather strange problem in C# around removal of whitespace.

我目前的code是这样的:

My current code looks like this:

string s = "This is a string without        spaces";
s = s.Replace(" ", string.Empty);

在这个例子中,最后的位已经结束时,无之后是一个缩进(制表),而不是实际空格的空格。显然,与string.replace不关心这一点,所以它忽略它,树叶空白在那里。

In this example, the last spaces at the end, after "without" is a indent (Tab) and not actually Spacebar spaces. Apparently String.Replace doesn't care about that, so it ignores it, and leaves THAT whitespace there.

有没有可能避免这个问题?

Is it possible to avoid this issue?

推荐答案

是的。删除制表符太:

string s = "This is a string without        spaces";
s = s.Replace(" ", string.Empty);
s = s.Replace("t", string.Empty);
阅读全文

相关推荐

最新文章