"Hello World" to "Hello\sWorld"

  • Thread starter Thread starter ME
  • Start date Start date
M

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
 
ME said:
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?
 
Thanks, that will do nicely!

Matt
Jon Skeet said:
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?
 
Back
Top