PC Review


Reply
Thread Tools Rate Thread

regex in resx

 
 
=?Utf-8?B?S05H?=
Guest
Posts: n/a
 
      2nd Apr 2006
When storing a regular expression in a resource file then extract using
"Resources.xxxx" all backslashes are now escaped. Is this normal behaviour
and if so how do I get back the actual value.
 
Reply With Quote
 
 
 
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      2nd Apr 2006
KNG <(E-Mail Removed)> wrote:
> When storing a regular expression in a resource file then extract using
> "Resources.xxxx" all backslashes are now escaped. Is this normal behaviour
> and if so how do I get back the actual value.


How are you determining that the backslashes are escaped? If you're
looking in the debugger, chances are that's the problem and the strings
are fine.

See http://www.pobox.com/~skeet/csharp/s....html#debugger

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Kevin Spencer
Guest
Posts: n/a
 
      2nd Apr 2006
I believe Jon is right. String literals are stored in resource files as
strings. Backslashes are used in code to allow the compiler to identify
literal characters as opposed to tokens. There is no need for them in a
resource file. And one of the "new things" in Visual Studio 2005 that really
irritates me is that the debugger inserts escape characters into the strings
it shows. Occasionally, I have had the experiences of copying text from a
Watch, only to have to manually un-escape it in order to view it in NotePad,
where I can see it more easily. I wonder if this feature is something one
can turn off somehow...

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

"Jon Skeet [C# MVP]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> KNG <(E-Mail Removed)> wrote:
>> When storing a regular expression in a resource file then extract using
>> "Resources.xxxx" all backslashes are now escaped. Is this normal
>> behaviour
>> and if so how do I get back the actual value.

>
> How are you determining that the backslashes are escaped? If you're
> looking in the debugger, chances are that's the problem and the strings
> are fine.
>
> See http://www.pobox.com/~skeet/csharp/s....html#debugger
>
> --
> Jon Skeet - <(E-Mail Removed)>
> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too



 
Reply With Quote
 
=?Utf-8?B?S05H?=
Guest
Posts: n/a
 
      3rd Apr 2006
Yep the debugger is indeed the problem in viewing the string, however, that
is not the answer it most certainly does not work using a resource directly
though I have now fixed the problem.

This does not work:
Regex.IsMatch( <string>, Resources.String1, RegexOptions.IgnoreCase )

But this does:
Regex.IsMatch( <string>, Regex.Unescape( Resources.String1 ),
RegexOptions.IgnoreCase )

"Jon Skeet [C# MVP]" wrote:

> KNG <(E-Mail Removed)> wrote:
> > When storing a regular expression in a resource file then extract using
> > "Resources.xxxx" all backslashes are now escaped. Is this normal behaviour
> > and if so how do I get back the actual value.

>
> How are you determining that the backslashes are escaped? If you're
> looking in the debugger, chances are that's the problem and the strings
> are fine.
>
> See http://www.pobox.com/~skeet/csharp/s....html#debugger
>
> --
> Jon Skeet - <(E-Mail Removed)>
> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too
>

 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      3rd Apr 2006
KNG <(E-Mail Removed)> wrote:
> Yep the debugger is indeed the problem in viewing the string, however, that
> is not the answer it most certainly does not work using a resource directly
> though I have now fixed the problem.
>
> This does not work:
> Regex.IsMatch( <string>, Resources.String1, RegexOptions.IgnoreCase )
>
> But this does:
> Regex.IsMatch( <string>, Regex.Unescape( Resources.String1 ),
> RegexOptions.IgnoreCase )


That sounds odd.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      5th Apr 2006
KNG <(E-Mail Removed)> wrote:
> Example project attached.


Well, the resource starts with \\A\\b etc - so it won't match a string
which doesn't have "\A\b" in it (without either of those slashes
meaning anything interesting).

It shows up as "\\A\\b" etc even in the resource designer - I assume
you actually want it to be "\A\b" etc. How did you enter it in the
first place?

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
 
Reply With Quote
 
=?Utf-8?B?S05H?=
Guest
Posts: n/a
 
      7th Apr 2006
Ah, now I know what happened. Doh!

The program I use to create the regex does not know about adding the "@" at
the front of the string so escapes the string. Me being a bit worse for the
lack of sleep at present just copied the string into the resource, when I did
the example application I should have put two and two together to see the
error of my ways.

It all now fits together.

Many thanx for your help and sorry to have troubled you with what was really
a silly mistake.



"Jon Skeet [C# MVP]" wrote:

> KNG <(E-Mail Removed)> wrote:
> > Example project attached.

>
> Well, the resource starts with \\A\\b etc - so it won't match a string
> which doesn't have "\A\b" in it (without either of those slashes
> meaning anything interesting).
>
> It shows up as "\\A\\b" etc even in the resource designer - I assume
> you actually want it to be "\A\b" etc. How did you enter it in the
> first place?
>
> --
> Jon Skeet - <(E-Mail Removed)>
> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
> If replying to the group, please do not mail me too
>

 
Reply With Quote
 
Jon Skeet [C# MVP]
Guest
Posts: n/a
 
      7th Apr 2006
KNG <(E-Mail Removed)> wrote:
> Ah, now I know what happened. Doh!
>
> The program I use to create the regex does not know about adding the "@" at
> the front of the string so escapes the string. Me being a bit worse for the
> lack of sleep at present just copied the string into the resource, when I did
> the example application I should have put two and two together to see the
> error of my ways.
>
> It all now fits together.
>
> Many thanx for your help and sorry to have troubled you with what was really
> a silly mistake.


No problem at all - a lot of mistakes look silly when you know what
they are. Very few of them look silly when you're stuck on them

--
Jon Skeet - <(E-Mail Removed)>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.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
Regex: different options on different sections of the Regex? Ethan Strauss Microsoft C# .NET 4 11th Jul 2008 04:54 PM
Standard strings only RESX files vs WinForms RESX files: How do you tell the difference? Johnny Kimble Microsoft C# .NET 0 7th Mar 2007 04:34 PM
Build action for the Resx file,.. Need the resx file outside DLL while publishing it.. Help needed Rahul Microsoft ASP .NET 0 28th Nov 2006 10:26 PM
switching from string.resx to string.en.resx marcwentink@hotmail.com Microsoft Dot NET 1 18th Oct 2006 03:55 PM
winforms and .resx files - 1.1 - $ appearing and .resx not linked? =?Utf-8?B?bmV0ZmxleA==?= Microsoft C# .NET 0 30th Mar 2006 08:06 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:01 PM.