By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,364 Members | 1,267 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,364 IT Pros & Developers. It's quick & easy.

"Hello World" to "Hello\sWorld"

P: n/a
ME
I am trying to find a prewritten method for converting a string like
this:"Hello World" to this "Hello\sWorld". I plan to use it to build a
regular expression. Specifically I am looking for a method that can convert
not just space (\s) but also any character that needs to be escaped in a
given string.

Thanks,

Matt
Jul 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
ME <tr*********@comcast.netREMOVETHIS> wrote:
I am trying to find a prewritten method for converting a string like
this:"Hello World" to this "Hello\sWorld". I plan to use it to build a
regular expression. Specifically I am looking for a method that can convert
not just space (\s) but also any character that needs to be escaped in a
given string.


Well, Regex.Escape will convert "Hello World" to "Hello\ World". This
is more exact than "Hello\sWorld" which would match *any* whitespace,
not just space. Is that okay for your purposes?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jul 21 '05 #2

P: n/a
ME
Thanks, that will do nicely!

Matt
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
ME <tr*********@comcast.netREMOVETHIS> wrote:
I am trying to find a prewritten method for converting a string like
this:"Hello World" to this "Hello\sWorld". I plan to use it to build a
regular expression. Specifically I am looking for a method that can
convert
not just space (\s) but also any character that needs to be escaped in a
given string.


Well, Regex.Escape will convert "Hello World" to "Hello\ World". This
is more exact than "Hello\sWorld" which would match *any* whitespace,
not just space. Is that okay for your purposes?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Jul 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.