Removing embedded (white) space from string

  • Thread starter Thread starter Julie
  • Start date Start date
J

Julie

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?
 
Use a regular expression:

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

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top