DotNet42 - The Answer to Your .NET Question
   
Home Blogs Groups Hot Topics Latest Topics

 
 

convert utf8 problem

Keywords: System, CSharp, Mail

  
Subject: convert utf8 problem
Newsgroup: microsoft.public.dotnet.languages.csharp
From: "dongxm"
Date: 30.10.2005 07:19:56
Is there a function can convert "abc" to "\u0097\u0098\u0099" in dotnet(c#)

 
  
Subject: Re: convert utf8 problem
Newsgroup: microsoft.public.dotnet.languages.csharp
From: Jon Skeet [C# MVP]
Date: 30.10.2005 07:57:05
dongxm <iamdbb@domainhidden> wrote:
[Original Message clipped]
Do you mean you want a string with the unicode escapes in? Note that
that isn't UTF-8, particuarly.
Note that "a" is \u0061 by the way - escape values are in hex, not
decimal.
This prints out the escaped version of the first command line parameter
you give it:
using System;
using System.Text;
public class foo
{
static void Main(string[] args)
{
StringBuilder builder = new StringBuilder(args[0].Length*6);
foreach (char c in args[0])
{
builder.Append("\\u");
builder.AppendFormat("{0:X4}", (int)c);
}
Console.WriteLine (builder.ToString());
}
}
See http://www.pobox.com/~skeet/csharp/unicode.html for more about
encodings, and http://www.pobox.com/~skeet/csharp/strings.html for more
about strings in general.
--
Jon Skeet - <skeet@domainhidden>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too