4

We have a program where the user needs to do a Copy-Paste of some content from Microsoft Word into a HTML editor (Visual Studio 2008).

That content in the HTML is then used in our confirmation emails.

Some of the characters like curly quotes turn into ? on the browser & in our confirmation email.

For the browser... I was able to find how to resolve this issue by using jQuery.

But for the confirmation email I cannot use JavaScript.

I tried this ASP.net / C# code but it hasn't worked for me.

if (s.IndexOf('\u201b') > -1) s = s.Replace('\u201b', '\'');  
if (s.IndexOf('\u201c') > -1) s = s.Replace('\u201c', '\"');  
if (s.IndexOf('\u201d') > -1) s = s.Replace('\u201d', '\"');  
if (s.IndexOf('\u201e') > -1) s = s.Replace('\u201e', '\"');  

I would appreciate any help in resolution.

Thanks.


Thank you all for your responses.

I am using the StreamReader to read the HTML file containing the Word characters.

string sFileText = "";  

StreamReader objReader = new StreamReader(sFilePath);  
sFileText = objReader.ReadToEnd();  
objReader.Close();  

return sFileText;  
Shog9
  • 156,901
  • 35
  • 231
  • 235
curiousR
  • 41
  • 1
  • 3
  • The code you tried in C# seems (semantically) correct to me. I don't have Word handy, unfortunately, but when you inspect the string in the debugger, zero-in on the smart quotes. Expand it and figure out it's index, then compare (ctrl-alt-q) `s[index] == '\u201b'` (or one of the other unicode characters you specified above). Presumably, you should be able to figure out what you need to do from there. – Kirk Woll Jun 25 '11 at 01:29
  • 1
    Indeed. I followed the question steps on http://www.coderun.com/ide/?w=jqURWxIWFUe1gNIFTYeAxA (click 'Run', then click the button. Source with Word quotes is in Default.aspx.cs). Probably the HTML editor is the problem then. – Niloct Jun 25 '11 at 01:43
  • possible dupe http://stackoverflow.com/questions/832020/how-do-you-deal-with-the-special-characters-that-ms-word-adds alternatively try copying into notepad first then into VS – Daniel Powell Jun 25 '11 at 01:40

1 Answers1

4

I did this and its work

   s = s.Replace('\u201b', '\'')
        .Replace('\u201c', '\"')
        .Replace('\u201d', '\"')
        .Replace('\u201e', '\"');

You can use the s.Contains ('\u201e'), instead of the IndexOf

Aristos
  • 66,005
  • 16
  • 114
  • 150