PC Review


Reply
Thread Tools Rate Thread

"Hello World" to "Hello\sWorld"

 
 
ME
Guest
Posts: n/a
 
      23rd Jun 2005
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


 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      23rd Jun 2005
ME <(E-Mail Removed)> 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 - <(E-Mail Removed)>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
ME
Guest
Posts: n/a
 
      23rd Jun 2005
Thanks, that will do nicely!

Matt
"Jon Skeet [C# MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> ME <(E-Mail Removed)> 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 - <(E-Mail Removed)>
> http://www.pobox.com/~skeet
> If replying to the group, please do not mail me too



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[Click the star to watch this topic] "bollywood actress""bollywood wallpapers" "bollywood news" "bollywood movies" "bollywood videosongs" "bollywood masala" "bollywood" "b Naeem Microsoft C# .NET 0 4th Jan 2010 07:57 AM
Field Names: "LongName", "ShortName", "Code", "Description","Comments" PeteCresswell Microsoft Access 2 26th Feb 2009 12:41 AM
"Hello World" to "Hello\sWorld" ME Microsoft Dot NET Framework 2 23rd Jun 2005 08:47 PM
"Hello World" to "Hello\sWorld" ME Microsoft VC .NET 2 23rd Jun 2005 08:47 PM
<FORM METHOD="post" onSubmit="return fieldcheck()" name="orientation" action="http://ws-kitty.BU.edu/AT/survey/orientation/script/write.asp" language="JavaScript"> Joeyej Microsoft ASP .NET 0 4th Jun 2004 09:55 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:53 PM.