Suresh Behera

The Microsoft .Net Junkies

News

Blogroll

Reading

Single and Double Quote for XML document

On my last article we are talking about replacing special character for XML document which was working great but our testing team able to break it again. The single and double quote character are different from NOTEPAD to Microsoft Word .Here is how it looks and it's decimal/Hex value

 

SINGLE QUOTE

NOTEPAD

Microsoft WORD

OPENING

CLOSING

OPENING

CLOSING

'

DEC  '

HEX  '

'

DEC  '

HEX  '

DEC    ‘

HEX    ‘

DEC  ’

HEX  ’

 

DOUBLE QUOTE

NOTEPAD

Microsoft WORD

OPENING

CLOSING

OPENING

CLOSING

"

DEC "

HEX "

"

DEC "

HEX "

DEC “

HEX “

DEC ”

HEX ”

Again, How do you replace in C# code ?
The best way it to write a Regular Expression but for quick solution use this code

newString = newString.Replace("'","'");

//" Double Quote Word oepning
newString = newString.Replace(""","“");

//" Double Quote Word Closing
newString = newString.Replace(""","”");

//‘ Single Quote Word oepning
newString = newString.Replace("‘","‘");

//’ Single Quote Word Closing
newString = newString.Replace("’","’");

How do you write or produce C# code for  Microsoft Word Single Quote  like this (not like ')
?
Well, To be frank I did not found any keyboard letter to write this character ;) Use the traditional method like copy the character from Microsoft Word and paste in VS .Net C# editor. Just like above and this works for other characters too.

For example :
The string conversation might look like this

Before :
This’s testing for “Double quote from MS word” and ‘single quote from MS Word’  'NOTEPAD' \"NOTEPAD\"

After  :
This’s testing for “Double quote from MS word” and ‘single quote from MS Word’  'NOTEPAD' \"NOTEPAD\"

Here is the link to convert character

Hope you enjoy this coding..Keep tune lots more fun part is coming up :)

Suresh Behera

 

 

 

 

Posted: Feb 28 2006, 05:04 PM by Suresh Behera | with 2 comment(s)
Filed under: ,

Comments

Saravanan Lakshmanan said:

Good post.  I have a similar situation where a WordML document has to be saved to a SQL server 2005 as XML data type.  When I try to insert, SQL Server errors out, not recognizing MS WORD's quote chars.  Interestingly, the WORDML file opens fine in most of the applications includnig VS2005 and IE... Is this a SQL 2005 specific issue? ...any tips to get around this problem?

thanks

Saravanan L

# August 18, 2006 12:42 PM

Shawn McCollum said:

try holding alt and typing 0145 then increment up to get both types of single and double quotes that word uses.  Charmap is a good way to find this stuff out.

# August 19, 2008 11:39 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)