473,320 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Ansi to UTF-8

Hi, help me to convert characters from Ansi to UTF-8.

I have been trying by using System.Text.Encoding.Convert to change the bytes from Ansi to UTF-8.

It is getting converted to different chinese along with the unicode symbols.
Nov 15 '06 #1
1 23217
Did you mean to say ASCII rather than ANSI?

Here is an example (in C#) of converting from ASCII encoded bytes to UTF-8:

Expand|Select|Wrap|Line Numbers
  1.  
  2.     // create a string to convert to a byte array...
  3.     String someText = "some ascii text to convert";
  4.     Console.WriteLine(someText);
  5.  
  6.     // encode the string as an ASCII byte array
  7.     byte[] myASCIIBytes = Encoding.ASCII.GetBytes(someText);
  8.     Console.WriteLine(BitConverter.ToString(myASCIIBytes));
  9.  
  10.     // convert the ASCII byte array to a UTF-8 byte array
  11.     byte[] myUTF8Bytes = ASCIIEncoding.Convert(Encoding.ASCII,
  12.          Encoding.UTF8, myASCIIBytes);
  13.     Console.WriteLine(BitConverter.ToString(myUTF8Bytes));
  14.  
  15.     // reconstitute a string from the UTF-8 byte array 
  16.     String deserialisedText = Encoding.UTF8.GetString(myUTF8Bytes);
  17.     Console.WriteLine(deserialisedText);
  18.  
  19.     //... only convert ASCII characters in the
  20.     // range 0x00 - 0x7F to avoid loss of value. 
  21.  
  22.     // ...
  23.  
Hope this helps.
Nov 15 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: aa | last post by:
Is it OK to include an ANSI file into a UTF-8 file?
2
by: Mark Anderson | last post by:
Hi, I've a problem with code that should produce a Windows(ANSI) encoded text file but doesn't. Server is IIS 5 on Win 2k, with ASP ver? My ASP uses data from an upstream HTML form on a UTF-8...
7
by: Hans | last post by:
Hi, I need to process files that are created in UTF-7 format. This works fine upto the point where a '+' character (0x2B/43) appears in the line. The string is mutilated... The reader appears...
2
by: Ziver MALHASOGLU | last post by:
Hi, I produce a text file using my windows application written with c#. -- System.Text.Encoding encOutput=null; encOutput=System.Text.Encoding.UTF8; StreamWriter sw=new...
5
by: Meenu Mehta | last post by:
I have a question. how to generate two files, one in UTF-8, the other in ASCII with the same column length SO that when i do the conversion from utf-8 to ascii or vice versa, the column length...
4
by: Julia | last post by:
Hi, I need to convert unicode string to ansi string Thanks in adavance.
2
by: jmhmaine | last post by:
During the course of development cycle I receive HTML files from designers that use Macs and PCs, but use tools other then Visual Studio. So these files sometimes are not UTF-8 Encoded. I see...
4
by: Nick | last post by:
Hi, I am trying to output a string of chinese characters as a text file. When I open a file for writing from VB, the file is automatically set to UTF-8 encoding (can tell by opening the file...
11
by: LucaJonny | last post by:
Hi, I've got a problem using StreamReader in VB.NET. I try to read a txt file that contains extended characters and theese are removed from the line that is being read. I've read a lot of...
10
by: Jed | last post by:
I have a form that needs to handle international characters withing the UTF-8 character set. I have tried all the recommended strategies for getting utf-8 characters from form input to email...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.