471,349 Members | 1,127 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

"Hello World" to "Hello\sWorld"

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
2 2002
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
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.

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.