CharsetDetector / UTF-unknown

Character set detector build in C# - .NET 5+, .NET Core 2+, .NET standard 1+ & .NET 4+

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use it with powershell/core script

dahikino opened this issue · comments

Hello,

I try to load the dll as module but i can't find the way to use the class CharsetDetector, with issue result :
New-Object: A constructor was not found. Cannot find an appropriate constructor for type UtfUnknown.CharsetDetector.

Have you any idea how to do it ?

Best regards

Hi, could you please provide an example?

Finally i found how to do it in a file script:

Add-Type -Path .\UtfUnknown.dll
[UtfUnknown.CharsetDetector]::DetectFromFile($filePath)

This is a example for the method DetectFromFile.
If you want only the code charset as result :

Add-Type -Path .\UtfUnknown.dll
[UtfUnknown.CharsetDetector]::DetectFromFile($filePath).detected.EncodingName.ToString()

Refering in the xml to other methods, replace DetectFromFile method by the one you need !

More generally, the syntax using .Net library in Powershell is :
[namespace.classname]::method

Thanks for sharing!

Closing as self answered. Thanks again :)