954,168 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Text file encoding

Hello :

How can I by programming, change the encoding of the text file,, I want to open a text file but I couldn't because it's encode in ANSI I want to change it to another encoding type???

Thanks

aminit
Junior Poster in Training
78 posts since Feb 2008
Reputation Points: 10
Solved Threads: 0
 

I think you need more details to describe your exact problem as I don't believe the obvious answer is really your question. The obvious answer being: Open up the text file in ANSI, encode the data and write to output file.

$dunk$
Newbie Poster
23 posts since Mar 2008
Reputation Points: 14
Solved Threads: 5
 

Firstly you should open Up your ANSI file with Its encoding then store in a String or something like that then apply your Encoding algorithm to it.

mzd12111
Light Poster
48 posts since Nov 2006
Reputation Points: 7
Solved Threads: 0
Infraction Points: 5
 

Hello :

How can I by programming, change the encoding of the text file,, I want to open a text file but I couldn't because it's encode in ANSI I want to change it to another encoding type???

Thanks

Hello,
try this code, it converts txt files from encoding1 to encoding2
in the following code i am converting any encoding to CodePage1256

using (Stream fileStream = new FileStream(file.FileLocation, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
using (Stream destStream = new FileStream(destinationPath, FileMode.Create, FileAccess.Write,
FileShare.ReadWrite))
{
using (var reader = new BinaryReader(fileStream))
{
using (var writer = new BinaryWriter(destStream, Encoding.GetEncoding(1256)))
{
var srcBytes = new byte[fileStream.Length];
reader.Read(srcBytes, 0, srcBytes.Length);

writer.Write(srcBytes);

}
}
}
}

Good Luck

GenyPOP
Newbie Poster
1 post since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You