By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,984 Members | 1,040 Online
Bytes IT Community
Submit an Article
Got Smarts?
Share your bits of IT knowledge by writing an article on Bytes.

Removing all spaces from inside a string value in VB.NET

P: 1
Source
Expand|Select|Wrap|Line Numbers
  1.  
  2. Public Function NoWhiteSpace(ByVal strText As String) As String
  3.    Return System.Text.RegularExpressions.Regex.Replace(strText, " ", _
  4.    String.Empty, System.Text.RegularExpressions.RegexOptions.IgnoreCase)
  5. End Function
  6.  
Demo
Expand|Select|Wrap|Line Numbers
  1. Dim Test As String = " This is a simple test for No white spaces function "
  2. Console.WriteLine("The original text is [{0}] and the replacement is [{1}]", _
  3.       Test, RemoveWhiteSpace(Test))
  4.  
Dec 19 '07 #1
Share this Article
Share on Google+
2 Comments


Plater
Expert 5K+
P: 7,872
Hmmm, seems overkill for already created abilities.


This removes all spaces in the string
Expand|Select|Wrap|Line Numbers
  1. Dim Test As String = " This is a simple test for No white spaces function "
  2. Test=Test.Replace(" ", String.Empty)
  3.  
This removes leading/trailing spaces.
Expand|Select|Wrap|Line Numbers
  1. Dim Test As String = " This is a simple test for No white spaces function "
  2. Test=Test.Trim(" ")
  3.  
Dec 19 '07 #2

P: 1
I'm sure the first method works fine, but I needed a simple (Non-Programmer) way to replace " " with "+" for Google Maps. Plater's method was about as easy as it gets. Thanks
Mar 11 '10 #3