473,385 Members | 1,597 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,385 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 2154
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 thread has been closed and replies have been disabled. Please start a new 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.