• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 790
  • Last Modified:

Convert a Encoding of a file in c sharp


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
  • 3
1 Solution
mannsingh3Author Commented:
Thanks in advance
Todd GerbertIT ConsultantCommented:
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

mannsingh3Author Commented:
it does not work
mannsingh3Author Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now