-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathDetectFile.cs
35 lines (32 loc) · 1.01 KB
/
DetectFile.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
using System;
using System.IO;
using UtfUnknown;
namespace ConsoleExample
{
public class DetectFile
{
/// <summary>
/// Command line example: detects the encoding of the given file.
/// </summary>
/// <param name="args">a filename</param>
public static void Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("Usage: ConsoleExample <filename>");
return;
}
var filename = args[0];
if (!File.Exists(filename))
{
Console.WriteLine($"File not found: {filename}");
return;
}
var result = CharsetDetector.DetectFromFile(filename);
var message = result.Detected != null
? $"Detected encoding {result.Detected.Encoding.WebName} with confidence {result.Detected.Confidence}."
: $"Detection failed: {filename}";
Console.WriteLine(message);
}
}
}