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