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
Removing all spaces in a string
提问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
回答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(" ","")
with great success.
我已经使用str=str.Replace(" ","")
得非常成功。
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)