Solved

Convert a Encoding of a file in c sharp

Posted on 2011-03-08
4
763 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Suggested Solutions

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 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