Replace double quotes (") with single quotes (')

G

Guest

Hi,

I need to replace all the double quotes (") in a textbox with single quotes ('). I used this code

text= Replace(text, """", "'"

This works fine (for normal double quotes).The problem comes in when you copy a double quote from MS Word and paste it in the text box. What happens is the double quote becomes slanted (“) so my code above can't filter it. I tried to do this

text= Replace(text, "““","'")

but what happens is that after typing this in visual studio, vb automatically converts it to the normal double quote ("). I already tried

text= Replace(text, chr(34), "'") ' 34 is the ascii of double quotes (")

but still, it won't work. I can't seem to find the ascii of the slanted double quotes, they somehow look all the same to me

Is there a work around for this

Thanks.
 
J

Jay B. Harlow [MVP - Outlook]

Gar,
I can't seem to find the ascii of the slanted double quotes,
they somehow look all the same to me
There is no ASCII for a Double Quote, there is an ANSI for Double Quote,
however I would recommend Unicode instead, so as to avoid
internationalization issues (read different ANSI code pages). You can use
Character Map under "Start - Programs - Accessories - System Tools" to find
the Unicode code point for the different typographic quote chars available.

Try something like:

' what most people think of quote chars
Const Apostrophe As Char = ChrW(&H27) ' single quotes
Const Quote As Char = ChrW(&H22) ' double quotes

' various typographic quote characters
Const LeftSingleQuote As Char = ChrW(&H2018)
Const RightSingleQuote As Char = ChrW(&H2019)
Const LeftDoubleQuote As Char = ChrW(&H201C)
Const RightDoubleQuote As Char = ChrW(&H201D)

' other typographic quote characters (international)
' Note: HP48 uses these for delimiters
Const LeftPointingDoubleAngleQuote As Char = ChrW(&HAB)
Const RightPointingDoubleAngleQuote As Char = ChrW(&HBB)

' other typographic quote characters (international)
Const SingleLow9Quote As Char = ChrW(&H201A)
Const SingleHighReversed9Quote As Char = ChrW(&H201B)
Const DoubleLow9Quote As Char = ChrW(&H201E)

' simulate cut & paste from Word
Dim text As String = LeftDoubleQuote & "This is a test" &
RightDoubleQuote

text = text.Replace(LeftDoubleQuote, Apostrophe)
text = text.Replace(RightDoubleQuote, Apostrophe)

Note I included most of the various typographic quote characters. The four
that are commonly used by Word (in the US) are LeftSingleQuote,
RightSingleQuote, LeftDoubleQuote and RightDoubleQuote.

For details on quote chars & typographic quote chars see:
http://www.amazon.com/exec/obidos/tg/detail/-/0938151495/104-3220013-7967152?v=glance

Hope this helps
Jay


gar said:
Hi,

I need to replace all the double quotes (") in a textbox with single quotes ('). I used this code:

text= Replace(text, """", "'")

This works fine (for normal double quotes).The problem comes in when you
copy a double quote from MS Word and paste it in the text box. What happens
is the double quote becomes slanted (") so my code above can't filter it. I
tried to do this:
text= Replace(text, """","'")

but what happens is that after typing this in visual studio, vb
automatically converts it to the normal double quote ("). I already tried:
text= Replace(text, chr(34), "'") ' 34 is the ascii of double quotes (")

but still, it won't work. I can't seem to find the ascii of the slanted
double quotes, they somehow look all the same to me
 
J

Jay B. Harlow [MVP - Outlook]

Gar,
I should add that there is no ASCII Left Double Quote, as ASCII is a 7 bit
code point (chars 0 to 127), while ANSI is 8 bit code point (chars 0 to
255). Where chars 0 to 127 are the same as ASCII, while chars 128 to 255
vary depending on local.

Unicode allows for millions of code points, so the need for code pages found
in ANSI is eliminated...

Also: Chr & Asc deals with ANSI code points, while ChrW & AscW deals with
Unicode code points.

Hope this helps
Jay

gar said:
Hi,

I need to replace all the double quotes (") in a textbox with single quotes ('). I used this code:

text= Replace(text, """", "'")

This works fine (for normal double quotes).The problem comes in when you
copy a double quote from MS Word and paste it in the text box. What happens
is the double quote becomes slanted (") so my code above can't filter it. I
tried to do this:
text= Replace(text, """","'")

but what happens is that after typing this in visual studio, vb
automatically converts it to the normal double quote ("). I already tried:
text= Replace(text, chr(34), "'") ' 34 is the ascii of double quotes (")

but still, it won't work. I can't seem to find the ascii of the slanted
double quotes, they somehow look all the same to me
 
C

Cor Ligthert

Hi Jay,

Will you point me for a good link for those Unicodes, I see you have them
mostly all or is it from a book?

Cor
 
C

Cor Ligthert

Hi Jay,

I never knew that this was possible.
Makes things again a lot easier.

:)

Thanks

Cor
 

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

Top