By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,972 Members | 883 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,972 IT Pros & Developers. It's quick & easy.

Storing regular expressions in string variables

P: n/a
VS magazine 11 04 shows how to use regular expression fro parsing text file.
I have problem storing the following expression in a string variable:
^\s*(<q1>("|'))(?<firstname>.*)\k<q1>\s*$

the single quote (') turns the rest of the string into an in line comment!
Can you please how to handle this?
Thanks
Bill

Nov 21 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Are you trying to do this?

Dim S as string
S = "^\s*(<q1>(""|'))(?<firstname>.*)\k<q1>\s*$"

Chris

"Bill Nguyen" <bi*****************@jaco.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
VS magazine 11 04 shows how to use regular expression fro parsing text
file.
I have problem storing the following expression in a string variable:
^\s*(<q1>("|'))(?<firstname>.*)\k<q1>\s*$

the single quote (') turns the rest of the string into an in line comment!
Can you please how to handle this?
Thanks
Bill

Nov 21 '05 #2

P: n/a
"Bill Nguyen" <bi*****************@jaco.com> schrieb:
VS magazine 11 04 shows how to use regular expression fro parsing text
file.
I have problem storing the following expression in a string variable:
^\s*(<q1>("|'))(?<firstname>.*)\k<q1>\s*$

the single quote (') turns the rest of the string into an in line comment!


Replace all double quote characters inside the string literal with two
successive double quotes.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3

P: n/a
Errata:

"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb:
Replace all double quote characters inside the string literal with two
successive double quotes.


"successive" -> "consecutive".

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 21 '05 #4

P: n/a
This seemed to work, however, it doesn't solve the problem of removing the
quotes around the field values.
I tried to use string.Replace to change double quotes (") to single quote
(') but double quotes gain gave me problem.
for example, I want to change "Value 1" to 'Value 1'
What's the chr() value for single quote and double quotes in VB.NET?
Thanks
Bill
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:uB**************@TK2MSFTNGP09.phx.gbl...
Are you trying to do this?

Dim S as string
S = "^\s*(<q1>(""|'))(?<firstname>.*)\k<q1>\s*$"

Chris

"Bill Nguyen" <bi*****************@jaco.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
VS magazine 11 04 shows how to use regular expression fro parsing text
file.
I have problem storing the following expression in a string variable:
^\s*(<q1>("|'))(?<firstname>.*)\k<q1>\s*$

the single quote (') turns the rest of the string into an in line comment! Can you please how to handle this?
Thanks
Bill


Nov 21 '05 #5

P: n/a
If I understand your problem you have this:

//Not tested
Dim S As String
S = ""Value 1"" ' Now S equals "Value 1"
S = S.Replace(""", "'")
messagebox.show(S) 'Now S equals 'Value 1'

Does that help?
Chris

"Bill Nguyen" <bi*****************@jaco.com> wrote in message
news:uD**************@TK2MSFTNGP11.phx.gbl...
This seemed to work, however, it doesn't solve the problem of removing the
quotes around the field values.
I tried to use string.Replace to change double quotes (") to single quote
(') but double quotes gain gave me problem.
for example, I want to change "Value 1" to 'Value 1'
What's the chr() value for single quote and double quotes in VB.NET?
Thanks
Bill
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
wrote
in message news:uB**************@TK2MSFTNGP09.phx.gbl...
Are you trying to do this?

Dim S as string
S = "^\s*(<q1>(""|'))(?<firstname>.*)\k<q1>\s*$"

Chris

"Bill Nguyen" <bi*****************@jaco.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
> VS magazine 11 04 shows how to use regular expression fro parsing text
> file.
> I have problem storing the following expression in a string variable:
> ^\s*(<q1>("|'))(?<firstname>.*)\k<q1>\s*$
>
> the single quote (') turns the rest of the string into an in line comment! > Can you please how to handle this?
> Thanks
> Bill
>
>
>



Nov 21 '05 #6

P: n/a
Chris;

I had to use chr(34) in lieu of """.
S = S.Replace(""", "'") -> not working
S = S.Replace(chr(34), "'") -> working.

Thanks for your help.
Bill

"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com> wrote
in message news:%2****************@TK2MSFTNGP14.phx.gbl...
If I understand your problem you have this:

//Not tested
Dim S As String
S = ""Value 1"" ' Now S equals "Value 1"
S = S.Replace(""", "'")
messagebox.show(S) 'Now S equals 'Value 1'

Does that help?
Chris

"Bill Nguyen" <bi*****************@jaco.com> wrote in message
news:uD**************@TK2MSFTNGP11.phx.gbl...
This seemed to work, however, it doesn't solve the problem of removing the quotes around the field values.
I tried to use string.Replace to change double quotes (") to single quote (') but double quotes gain gave me problem.
for example, I want to change "Value 1" to 'Value 1'
What's the chr() value for single quote and double quotes in VB.NET?
Thanks
Bill
"Chris, Master of All Things Insignificant" <chris@No_Spam_Please.com>
wrote
in message news:uB**************@TK2MSFTNGP09.phx.gbl...
Are you trying to do this?

Dim S as string
S = "^\s*(<q1>(""|'))(?<firstname>.*)\k<q1>\s*$"

Chris

"Bill Nguyen" <bi*****************@jaco.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
> VS magazine 11 04 shows how to use regular expression fro parsing text > file.
> I have problem storing the following expression in a string variable:
> ^\s*(<q1>("|'))(?<firstname>.*)\k<q1>\s*$
>
> the single quote (') turns the rest of the string into an in line

comment!
> Can you please how to handle this?
> Thanks
> Bill
>
>
>



Nov 21 '05 #7

P: n/a
"Bill Nguyen" <bi*****************@jaco.com> schrieb:
I had to use chr(34) in lieu of """.
S = S.Replace(""", "'") -> not working


Please read the answers other people give you! Every double quote is
encoded as /two/ consecutive double quotes.

\\\
s = s.Replace(""""c, "'"c)
///

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.