Storing regular expressions in string variables

  • Thread starter Thread starter Bill Nguyen
  • Start date Start date
B

Bill Nguyen

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
 
Are you trying to do this?

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

Chris
 
Bill Nguyen said:
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.
 
Errata:

Herfried K. Wagner said:
Replace all double quote characters inside the string literal with two
successive double quotes.

"successive" -> "consecutive".
 
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
 
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
 
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
 
Bill Nguyen said:
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)
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top