String to Char conversion involving Unicode characters
Hi Guys
Suppose I construct a string (mind you - not hardcode) and that string is made up of a series of unicode character representations like "\u0625\u062D... " and so on.
If I display this string, all I get is the string as it is - instead of the unicode characters that it is supposed to represent.
The same string if I make a direct assignment (hardcode) to it like -
str = "\u0625\u062D"
it works well.
Where as suppose (another example for what I am trying to explain) if have a string like -
str = "AAA [U] BBB";
and, I try doing something like -
str = str.Replace("[U]","\u0625")
and, then try printing str, it fails :(
I guess I am missing out on some 'string to char' conversion somewhere, please help.
Thanks
Suhaib
Re: String to Char conversion involving Unicode characters
Have you tried :
Code:
string sString1 = "AAA [U] BBB";
string sReplace = "\u0625";
sString1 = sString1.Replace("[U]", sReplace);
Ah - just found this in MSDN :
ms-help://MS.VSCC.2003/MS.MSDNQTR.2003FEB.1033/csspec/html/vclrfcsharpspec_2_4_1.htm
It says that
Quote:
A Unicode character escape sequence represents a Unicode character. Unicode character escape sequences are processed in identifiers (Section 2.4.2), character literals (Section 2.4.4.4), and regular string literals (Section 2.4.4.5). A Unicode character escape is not processed in any other location (for example, to form an operator, punctuator, or keyword).
so that's why it doesn't work as an operator !
Darwen.
Re: String to Char conversion involving Unicode characters
string sString1 = "AAA [U] BBB";
string sReplace = "\u0625";
sString1 = sString1.Replace("[U]", sReplace);
Smart work that was Darwen :)
I wonder why it never occured to me.
I kept trying a direct substituion all the while.
Thank you so much.