CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2003
    Location
    Bangalore, INDIA
    Posts
    180

    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

  2. #2
    Join Date
    Jan 2002
    Location
    Scaro, UK
    Posts
    5,940

    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

    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.
    Last edited by darwen; October 4th, 2004 at 11:07 AM.
    www.pinvoker.com - PInvoker - the .NET PInvoke Interface Exporter for C++ Dlls.

  3. #3
    Join Date
    Jan 2003
    Location
    Bangalore, INDIA
    Posts
    180

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured