473,406 Members | 2,698 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,406 software developers and data experts.

Removing embedded (white) space from string

I currently use the following to remove embedded spaces from strings:

dest = str.Replace(" ", "");

and resort to something like the following to remove white space:

dest = str.Replace(" ", "").Replace("\t", "").etc.;

Is there a better, more efficient way?
Nov 16 '05 #1
3 19620
Use a regular expression:

Regex r = new Regex(@"\s");
dest = r.Replace(str, "");

Ken
"Julie" <ju***@nospam.com> wrote in message
news:40***************@nospam.com...
I currently use the following to remove embedded spaces from strings:

dest = str.Replace(" ", "");

and resort to something like the following to remove white space:

dest = str.Replace(" ", "").Replace("\t", "").etc.;

Is there a better, more efficient way?

Nov 16 '05 #2
Ken Kolda wrote:

Use a regular expression:

Regex r = new Regex(@"\s");
dest = r.Replace(str, "");

Ken

"Julie" <ju***@nospam.com> wrote in message
news:40***************@nospam.com...
I currently use the following to remove embedded spaces from strings:

dest = str.Replace(" ", "");

and resort to something like the following to remove white space:

dest = str.Replace(" ", "").Replace("\t", "").etc.;

Is there a better, more efficient way?


Excellent -- thanks!
Nov 16 '05 #3
Ya know, sometime I have GOT to learn more about regular expressions. I've never really been able to grasp the concept of them,
though I know they are very powerful.

--
Adam Clauss
ca*****@tamu.edu
"Ken Kolda" <ke*******@elliemae-nospamplease.com> wrote in message news:OQ**************@TK2MSFTNGP11.phx.gbl...
Use a regular expression:

Regex r = new Regex(@"\s");
dest = r.Replace(str, "");

Ken
"Julie" <ju***@nospam.com> wrote in message
news:40***************@nospam.com...
I currently use the following to remove embedded spaces from strings:

dest = str.Replace(" ", "");

and resort to something like the following to remove white space:

dest = str.Replace(" ", "").Replace("\t", "").etc.;

Is there a better, more efficient way?



Nov 16 '05 #4

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

Similar topics

6
by: Grumble | last post by:
Hello all, I want to read lines from a text file, where each line has the following syntax: token1:token2:token3 There could be white space between tokens and ':'
5
by: Jonathan Daggar | last post by:
Hello, I'm trying to put together a form with a very tight table formatting. However, every time I put an text-type input field in, the browser pads the area to the right of it with space. I've...
8
by: Peter O'Reilly | last post by:
I have an HTML form with a textarea input box. When the user conducts a post request (e.g. clicks the submit button), an HTML preview page is presented to them with the information they have...
2
by: vbMark | last post by:
I need to check for sentences that have a space before the period and remove the space. I've tried: $sentence = str_replace(" .", ".", $sentence); but it does not work. I've tried other ways...
11
by: gopal srinivasan | last post by:
Hi, I have a text like this - "This is a message containing tabs and white spaces" Now this text contains tabs and white spaces. I want remove the tabs and white...
16
by: Charles Law | last post by:
I have a string similar to the following: " MyString 40 "Hello world" all " It contains white space that may be spaces or tabs, or a combination, and I want to produce an array...
4
by: clickon | last post by:
I am building up the validation expression for a RegularExpresionValidator control by retreiving some values from a database and looping through the DataTable to build and adding lots of |...
5
by: Richard Maher | last post by:
Hi, Can someone please show me how to tell Firefox to preseve white-space when returning the selectList.option.value attribute? I have change the style so that the white-space is preserved on...
4
by: mosesdinakaran | last post by:
Can any one explain how the rule is applied for the following Regular expression $Str = 'the red king'; $Pattern = '/((red|white) (king|queen))/'; preg_match($Pattern,$Str,$Val); Result:
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.