ReadJEnc C#(.NET) File Character Code Type Automatic Determination Library
C#(.NET Framework) Text file for automatic character code character recognition & reading library.
This is a character code auto-identification function of my own grep tool (TresGrep / HNXgrep) cut out as a library of C #.
// Specify the file whose character encoding is to be determined by FileInfo object etc.
void Example(System.IO.FileInfo file)
{
using (Hnx8.ReadJEnc.FileReader reader = new FileReader(file))
{
// Perform reading & detect encoding.
Hnx8.ReadJEnc.CharCode c = reader.Read(file);
// Get file-type name form the Name property. Get encoding object from the GetEncoding() method.
string name = c.Name;
Console.WriteLine("【" + name + "】" + file.Name);
System.Text.Encoding enc = c.GetEncoding();
// The actual readout character string can be obtained from the Text property.
// Note : For non-text-files, null is returned.
string text = reader.Text;
// From the type of return value, you can grasp the rough classification of the file.
if (c is CharCode.Text)
{
Console.WriteLine("-------------------------------------");
Console.WriteLine(text);
}
}
}
Hnx8.ReadJEnc.WinForm.Sample\SampleForm.cs
.The main part of the source code is briefly explained in the following blog article.
If you have any problems, doubts or impressions about this library, please give feedback to the appropriate articles of the author BLOG.
Issues,Pull requests will also accept contact.