1

I have a string and I am using GEMBOX SPREADSHEET

string sr = “Save as type”; 

In this -- Save as type -- is normal string but when i am loading a Text file Using GEMBOX

this Symbol

“Save as type”

is Converted to

�Save as type�

How to solve this Issue ? This is the Code comes when i try to Implement that

65533
John Saunders
  • 160,644
  • 26
  • 247
  • 397
Aravind
  • 177
  • 1
  • 3
  • 13

1 Answers1

5

You could use the following function to replace the special Word/Excel characters when you parse the data from the worksheets:

public static string ReplaceWordChars(this string text)
{
    var s = text;

    s = Regex.Replace(s, "[\u2018|\u2019|\u201A]", "'"); // smart single quotes and apostrophe
    s = Regex.Replace(s, "[\u201C|\u201D|\u201E]", "\""); // smart double quotes
    s = Regex.Replace(s, "\u2026", "..."); // ellipsis
    s = Regex.Replace(s, "[\u2013|\u2014]", "-"); // dashes
    s = Regex.Replace(s, "\u02C6", "^"); // circumflex
    s = Regex.Replace(s, "\u2039", "<"); // open angle bracket
    s = Regex.Replace(s, "\u203A", ">"); // close angle bracket
    s = Regex.Replace(s, "[\u02DC|\u00A0]", " "); // spaces

    return s;
}

This function does not replace all special characters, but only the most common ones used by Word/Excel.

I recently had the same problem while working on a webservice project, and came across this function during a Google search. This is the original article where I found the code: http://www.andornot.com/blog/post/Replace-MS-Word-special-characters-in-javascript-and-C.aspx

RiptoR
  • 466
  • 7
  • 5
  • I'm using that code from that site as well but have raised a query with the author. \u02DC is a tilde according to http://www.fileformat.info/info/unicode/char/2dc/index.htm and indeed typing ALT+732 in Word gives a tilde. – RyanfaeScotland Dec 03 '15 at 11:55