Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
| Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Professionals If you are an experienced ASP.NET programmer, this is the forum for your 3.5 questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Professionals section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 20th, 2011, 06:45 PM
Authorized User
 
Join Date: Sep 2006
Location: Belgrade, Serbia, Yugoslavia.
Posts: 37
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via MSN to VerbatimBOT Send a message via Yahoo to VerbatimBOT
Unhappy Convert encoded characters with escape sequence (\u03c1)

Hi all,
Does anyone have an idea how do I parse and convert properly character codes like '\u03c1'?
When I hardcode string like:
Code:
string str = "\u03c1";
MessageBox.Show(str);
it works good, but when I receive "\u03c1" as a string (from an input textbox), it treats that escape sequence not as "\u" but as "\\u" so it does not recognizes it.
Any help would be appreciated.

Thanks in advance,
Aleksandar
__________________
Aleksandar Dragosavac
Belgrade, Serbia
 
Old February 25th, 2011, 09:25 AM
Authorized User
Points: 448, Level: 7
Points: 448, Level: 7 Points: 448, Level: 7 Points: 448, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2011
Posts: 86
Thanks: 1
Thanked 12 Times in 12 Posts
Default Unicode string versus character

Hi,


I'm not sure what you'r trying to parse/convert...

When I enter the ρ character in a textbox and look at it in Quickwatch the value is 0x03c1 'ρ'.

Only when you past the unicode string as a string in a textbox you will see the text as "\\u03c1"..
 
Old February 25th, 2011, 09:30 AM
Authorized User
 
Join Date: Sep 2006
Location: Belgrade, Serbia, Yugoslavia.
Posts: 37
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via MSN to VerbatimBOT Send a message via Yahoo to VerbatimBOT
Default

Hi disel2010,

The thing was I couldn't convert "\\u" character to an actual "\u" char.
For instance, entering "\u03c1" in a TextBox and hardcoding it like string str="\u03c1" is not the same (the second one works as it should be).

But never mind, I found a way:
Code:
 StringBuilder sb = new StringBuilder();
            //string[] array = value.Replace("\\u", "").Split(' ');

            for (int i=0; i<value.Length - 4; i++)
            {
                if (value.Substring(i, 2) == "\\u")
                {
                    sb.Append((char)Int16.Parse(value.Substring(i + 2, 4), System.Globalization.NumberStyles.AllowHexSpecifier));
                    i += 5;
                }
                else
                    sb.Append(value[i]);
            }

            return sb.ToString().Trim();
Thanks for replying though.

All the best
__________________
Aleksandar Dragosavac
Belgrade, Serbia
 
Old February 25th, 2011, 09:44 AM
Authorized User
Points: 448, Level: 7
Points: 448, Level: 7 Points: 448, Level: 7 Points: 448, Level: 7
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2011
Posts: 86
Thanks: 1
Thanked 12 Times in 12 Posts
Post

Hi,

glad to see you worked it out yourself.

In seeing your code, I believe a CharEnumerator would have been nice too.
Something like this:
Code:
CharEnumerator txtInputEnum = txtBox1.Text.GetEnumerator();
while (txtInputEnum.MoveNext()){
           char c = txtInputEnum.Current;
           if (c.ToString() == "\u03c1")
                sb.Append('X');
            else
                sb.Append(c);
        }
Kind regards
The Following User Says Thank You to disel2010 For This Useful Post:
VerbatimBOT (February 25th, 2011)




Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT-escape-sequence sunilkswain XSLT 7 March 23rd, 2009 03:03 AM
how to send escape sequence to printer ergoktas C# 0 November 28th, 2006 04:36 AM
xslt issue to translate escape sequence rk2203 XSLT 2 October 13th, 2005 07:37 AM
how to escape special characters? reddygaru XML 2 December 16th, 2003 07:13 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.