473,378 Members | 1,580 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,378 software developers and data experts.

regex in resx

KNG
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.
Apr 1 '06 #1
7 1918
KNG <KN*@discussions.microsoft.com> 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 - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 2 '06 #2
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]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
KNG <KN*@discussions.microsoft.com> 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 - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Apr 2 '06 #3
KNG
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 <KN*@discussions.microsoft.com> 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 - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Apr 3 '06 #4
KNG <KN*@discussions.microsoft.com> 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 - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 3 '06 #5
KNG <KN*@noserver.com> 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 - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 4 '06 #6
KNG
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 <KN*@noserver.com> 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 - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too

Apr 6 '06 #7
KNG <KN*@discussions.microsoft.com> 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 - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 7 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: qh0st | last post by:
Hi all. I have an windows form application that will have multiple language ..resx files per form. Is there anyway I can bundle these .resx files into ONE .dll per form? If not, do you have any...
4
by: Todd Acheson | last post by:
TOOLS: Visual Studio.NET 2003 .NET SDK GOAL: Reproduce the DLL's that our Visual Studio.NET development boxes create, by using the SDK command line compilers DILLEMA: RESX Files, how to...
0
by: David Krussow | last post by:
I had an aspx page (mypage.aspx) with a code behind file (mypage.aspx.cs) that in turn had a resx file (mypage.aspx.resx). I decided to create another aspx page (myotherpage.aspx) that would reuse...
2
by: Paul | last post by:
I have plugged the ExceptionManagement app block into our framework and have a question about resource files. ExceptionManagerText.resx is one of resource files in the project. When you look at...
3
by: Servé La | last post by:
We have an aspnet project where 2 people are working on and we have put the source files into subversion. Thinking that they were not crucial for a project, we did not put in the resx files. But...
5
by: Franck | last post by:
Hello, I've just moved to visual developper 2005 to do so, I also had to use the convert assistant. what it did; moving my file resx files that i had in a diresctory called resx to a new...
0
by: prabhupr | last post by:
Hi Folks I'm currently working on a Localization+Globalization project; for this project, we need to generate ".Resx" files and we use "US English" Resx file as the base version, to compare the...
0
by: Steave | last post by:
Hi, using Managed C++ (.Net 2.0), I want to embed some images within an executable using a .resX file, and upon an event (in this case a combo box changing), I want the picture box to update with a...
8
by: raylopez99 | last post by:
I have the latest version of Visual Studio 2008 Professional, which allows you to create resource files (this is the .resx file, no?), unlike the Express version, which does not. I am trying to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.