Solved

Convert a Encoding of a file in c sharp

Posted on 2011-03-08
4
748 Views
Last Modified: 2012-05-11
Hi,

I have found couple of examples online for converting the encoding of file in c sharp, but the file I have is UCS-2 LE w//o BOM , can somebody please tell me how to convert this to another encoding say ascii
0
Comment
Question by:mannsingh3
  • 3
4 Comments
 

Author Comment

by:mannsingh3
Comment Utility
Thanks in advance
0
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 500 total points
Comment Utility
According to Wikipedia, UCS-2LE is equivelant to the first 60k code points of UTF-16, so:
static void UTF16ToASCII(string file)
{
	string contents = File.ReadAllText(file, Encoding.Unicode); // Read the file
	File.WriteAllText(file, contents, Encoding.ASCII); // Re-write it as ASCII
}

Open in new window

0
 

Author Comment

by:mannsingh3
Comment Utility
it does not work
0
 

Author Closing Comment

by:mannsingh3
Comment Utility
Thanks
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now