Skip to content

Latest commit

 

History

History
72 lines (61 loc) · 3.21 KB

File metadata and controls

72 lines (61 loc) · 3.21 KB

ReadJEnc

ReadJEnc C#(.NET) File Character Code Type Automatic Determination Library

Overview

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 #.

  • Compatible: .NET 2.0/3.5/4.0/4.5/4.6/4.7, .NET Core 1.0/1.1/2.0, .NET Standard 1.3/2.0

Where to get it

How does it work? (Japanese only)

Instructions

  • See the Example below.
	// 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);
	        }
	    }
	}

Other Supplement

The main part of the source code is briefly explained in the following blog article.

Library incorporation example

Contact

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.

License