tags:

views:

297

answers:

1

how do you remove spaces from a string in vb.net?

+5  A: 

to remove ALL spaces:

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

To remove Leading and trailing spaces:

Edit - added this removes any white space, so newlines, tabs, etc, would be removed.

myString = myString.Trim()
David Stratton
.Trim removes white-space characters. Might not be what he wants.
ElGringoGrande
Thank you @el.gringogrande.
David Stratton
Replace(" ", vbNullString) may run a hair faster, and (more importantly) be a bit clearer. YMMV.
Thom Smith