469,289 Members | 2,090 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Share your developer knowledge by writing an article on Bytes.

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

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
2 28367
Plater
7,872 Expert 4TB
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
ejm3
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

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by jalkadir | last post: by
11 posts views Thread by gopal srinivasan | last post: by
12 posts views Thread by Magix | last post: by
1 post views Thread by Gene Kelley | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.