vb.net 删除字符串中的所有空格

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4126934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 15:07:30  来源:igfitidea点击:

Removing all spaces in a string

vb.net

提问by Furqan Sehgal

Is there any function in vb.net that removes all spaces in a string. I mean a string like ' What is this' should be 'Whatisthis'

vb.net 中是否有任何函数可以删除字符串中的所有空格。我的意思是像“这是什么”这样的字符串应该是“Whatisthis”

Thanks Furqan

谢谢富尔坎

回答by Frédéric Hamidi

Use String.Replace()

使用String.Replace()

Dim s As String = " What is this"
s = s.Replace(" ", "")

回答by Brandon Montgomery

You could use String.Replace:

你可以使用 String.Replace:

Dim str As String = " What is this"
str = str.Replace(" ", "")

回答by Albert Monteiro

I have used str=str.Replace("&nbsp","")with great success.

我已经使用str=str.Replace("&nbsp","")得非常成功。

However, str=str.Replace(" ","")has not worked for me in the past.

但是,str=str.Replace(" ","")过去对我不起作用。

回答by user225312

Using String.Replace:

使用String.Replace

Dim Test As String = "Hello Hi"
Test = Test.Replace(" ", String.Empty)