HighTechTalks DotNet Forums  

Trim user input of spaces, tabs, and others

Dotnet Scripting microsoft.public.dotnet.scripting


Discuss Trim user input of spaces, tabs, and others in the Dotnet Scripting forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Shabam
 
Posts: n/a

Default Trim user input of spaces, tabs, and others - 10-09-2004 , 03:32 PM






Is there a function in dotnet that allows me to trim user input so that:

1) It gets rid of leading/trailing spaces, tabs, newlines and whatever other
non-printing characters
2) Gets rid of all tabs, newlines, and whatever other non-printing
characters anywhere else, preferably replacing them with one space
3) Takes any consecutive number of spaces and replace it with just one
space.




Reply With Quote
  #2  
Old   
Niki Estner
 
Posts: n/a

Default Re: Trim user input of spaces, tabs, and others - 10-09-2004 , 04:29 PM






"Shabam" <blislecp (AT) hotmail (DOT) com> wrote in
news:LtSdncD255eZ2fXcRVn-pQ (AT) adelphia (DOT) com...
Quote:
Is there a function in dotnet that allows me to trim user input so that:

1) It gets rid of leading/trailing spaces, tabs, newlines and whatever
other
non-printing characters
String.Trim does that - you can tell it what characters to trim, e.g:
myString = myString.Trim(' ', '\t', '\n', '\r');

Quote:
2) Gets rid of all tabs, newlines, and whatever other non-printing
characters anywhere else, preferably replacing them with one space
3) Takes any consecutive number of spaces and replace it with just one
space.
I'd suggest using a regular expression for that purpose:
myString = System.Text.RegularExpressions.Regex.Replace("\s+" , " ");
Depending on what characters you want to replace you might have to adjust
the search pattern.

Niki




Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.