字符串替换练习

时间:2011-06-28 18:01:32

标签: vb.net

如何替换此字符串,以便在替换工作后字符串将没有任何空格?

这是字符串:

dim InitialString as string = "Hello world !!!"

2 个答案:

答案 0 :(得分:3)

Dim myString As String = "Hello world !!!"

myString = myString.Replace(" ","")

答案 1 :(得分:1)

要使用字符串替换,您可以这样做:

dim InitialString as string = "Hello world !!!"
' We can use the Replace method like this
InitialString  = InitialString.Replace("world", "planet")
' InitialString now says "Hello planet !!!"

' We can remove the ' ' SPACE character by replacing it with an empty string
InitialString  = InitialString.Replace(" ", "")

' We release the resources that InitialString uses like this :
InitialString = NOTHING