Solved

Convert a Encoding of a file in c sharp

Posted on 2011-03-08
4
771 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 

Author Comment

by:mannsingh3
ID: 35071685
Thanks in advance
0
 
LVL 33

Accepted Solution

by:
Todd Gerbert earned 500 total points
ID: 35072493
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
ID: 35142056
it does not work
0
 

Author Closing Comment

by:mannsingh3
ID: 35142112
Thanks
0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

724 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