CharsetDetector / UTF-unknown

Character set detector build in C# - .NET 5+, .NET Core 2+, .NET standard 1+ & .NET 4+
303 stars 45 forks source link

How to use it with powershell/core script #123

Closed dahikino closed 3 years ago

dahikino commented 3 years ago

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

rstm-sf commented 3 years ago

Hi, could you please provide an example?

dahikino commented 3 years ago

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 !

dahikino commented 3 years ago

More generally, the syntax using .Net library in Powershell is :

304NotModified commented 3 years ago

Thanks for sharing!

304NotModified commented 3 years ago

Closing as self answered. Thanks again :)