How To Remove Spaces From String in VB.NET

Removing White Space From String In VB.NET

There Are Several Ways By Following Which We Can Remove Spaces Or Whitespace From String In Visual Basic.NET


Lets Start With Creating A New Project In Visual Studio. Add Two TextBoxes (TextBox1 For Accepting Text , TextBox2 For Returning Output i.e. Text Without Space) , One Button (On Pressing Space Will Be Removed)


Code For Removing Space

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim mytext As String = TextBox1.Text
        mytext = mytext.Replace(" ", "")
        TextBox2.Text = mytext
    End Sub

        
Or

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        TextBox2.Text = TextBox1.Text.Replace(" ", "")
    End Sub
        
These Are The Two Simple Method By Using Which We Can Remove Space/Whitespaces From String.

Output