Connecting Tech Pros Worldwide Help | Site Map
Reply
 
LinkBack Thread Tools Search this Thread
  #1  
Old December 19th, 2007, 08:34 PM
Newbie
 
Join Date: Dec 2007
Location: Oregon USA
Age: 52
Posts: 1
Default Removing all spaces from inside a string value in VB.NET

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.  

Last edited by Frinavale; December 10th, 2008 at 03:21 PM. Reason: removed non-code lines from code.
Reply



  #2  
Old December 19th, 2007, 09:10 PM
Plater's Avatar
Moderator
 
Join Date: Apr 2007
Location: New England
Posts: 6,720
Default

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.  
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.