Characters unrecognized in database

  • Thread starter Thread starter hb
  • Start date Start date
H

hb

How do I prevent an apostrophe or double quote copied from Word and pasted
into a textbox on my webform from being converted to upside down question
marks in my database?

I set the content type of the page with
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
- but this doesn't help.
 
While I'm not sure if it's possible to prevent those characters from being
sent to the server, I did a quick check and found that the codes for those
characters were:
single quote: 8216
double quote: 8221
while the ones you want are:
single quote: 39
double quote: 34

so, I would just go ahead and do a replace one the string I got back from
the user:

TextBox1.Text = TextBox1.Text.Replace((char)8216, (char)39);
TextBox1.Text = TextBox1.Text.Replace((char)8221, (char)34);

HTH,
-Cliff
 
forgot:
remember that if you are using an insert statement within your C#, you need
to replace single quote with two of them:

TextBox1.Text = TextBox1.Replace("'", "''");

-Cliff
 
Good info. How can I look up these codes myself? Your example got me
going, but it doesn't catch the opening double quotes (does get the closing
ones, though).
 
Nice find with the article... I'll have to keep a bookmark to that..

-Cliff
 

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

Back
Top