去除标签空白的? [英] Removal of Tab-whitespace?

查看:176
本文介绍了去除标签空白的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个很奇怪的问题,在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);

这篇关于去除标签空白的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆