[RESOLVED] [2005] Removing Space(s) within a string
Hi everyone!
I just wanna ask on how to remove space(s) within a string. For example, I have a string "Hello world" and my output should be "Helloworld".
I've already used the Trim Function but it won't give me the desired output.
Thanks a lot!
Radic
Re: [2005] Removing Space(s) within a string
Use the Replace method. Also, please provide descriptive titles for your threads.
Re: [2005] Removing Space(s) within a string
vb Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim s As String = "Hello World"
MessageBox.Show(s.Replace(" ", ""))
End Sub
Re: [RESOLVED] [2005] Removing Space(s) within a string
Re: [RESOLVED] [2005] Removing Space(s) within a string
This is a small thing and not specifically related to the question but you should not use literal empty strings. It is "more correct" to use the String.Empty property:
vb Code:
MessageBox.Show(s.Replace(" ", String.Empty))
Re: [RESOLVED] [2005] Removing Space(s) within a string
Re: [RESOLVED] [2005] Removing Space(s) within a string
Quote:
Originally Posted by jmcilhinney
This is a small thing and not specifically related to the question but you should not use literal empty strings. It is "more correct" to use the String.Empty property:
vb Code:
MessageBox.Show(s.Replace(" ", String.Empty))
Again Forget:bigyello:
Thanks for That:wave: