Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Professionals
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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
  #2 (permalink)  
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"..
  #3 (permalink)  
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
  #4 (permalink)  
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)
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 11:14 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.