473,387 Members | 3,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Trim user input of spaces, tabs, and others

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.

Jul 21 '05 #1
1 1827
"Shabam" <bl******@hotmail.com> wrote in
news:Lt********************@adelphia.com...
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');
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
Jul 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Reply Via Newsgroup | last post by:
Folks, In PHP and some other scripting languages, one has trim() - It removes newline, tabs and blank spaces that might prefix, or suffix a string. Can someone tell me how I can do this in...
5
by: Alex Vassiliev | last post by:
Hi all. Just wanted to share two handy RegEx expressions to strips leading and trailing white-space from a string, and to replace all repeated spaces, newlines and tabs with a single space. *...
5
by: Dave Bovey | last post by:
I created a church database in Access 97 that contain the typical Name, Address, and Phone Number information fields. I had a number of different reports to print query data in different formats. ...
4
by: santa19992000 | last post by:
can I use scanf to get input (some times user enters input sometimes not, just hit keyboard)?. It displays to enter IP address, if user wants to change, then he enters, otherwise he hits keyboard,...
1
by: Shabam | last post by:
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...
135
by: Xah Lee | last post by:
Tabs versus Spaces in Source Code Xah Lee, 2006-05-13 In coding a computer program, there's often the choices of tabs or spaces for code indentation. There is a large amount of confusion about...
3
by: Pascal | last post by:
bonjour hello I would like to trim a string of all its white spaces so i used myString.trim() but it doesn't work as supposed : unsecable space are remaining in the middle of my string... i...
3
by: BlackMustard | last post by:
hi all, i am having problems using the Trim() function in a program written in VB6. i'm getting my strings from reading a textfile line by line, but regardless of the trim function a couple of...
4
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I trim whitespace - trim/trimRight/trimLeft...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.