[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 783
  • Last Modified:

Convert a Encoding of a file in c sharp

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
mannsingh3
Asked:
mannsingh3
  • 3
1 Solution
 
mannsingh3Author Commented:
Thanks in advance
0
 
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

0
 
mannsingh3Author Commented:
it does not work
0
 
mannsingh3Author Commented:
Thanks
0

Featured Post

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

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