PowerShell Convert a File from utf-8 to ANSI (such as ...
文章推薦指數: 80 %
(PowerShell) Convert a File from utf-8 to ANSI (such as Windows-1252). This example is to satisfy a particular user's support question: I have a file that ... Chilkat HOME.NETCoreC# Android™ AutoIt C C# C++ Chilkat2-Python CkPython ClassicASP DataFlex DelphiActiveX DelphiDLL Go Java Lianja MonoC# Node.js Objective-C PHPActiveX PHPExtension Perl PowerBuilder PowerShell PureBasic Ruby SQLServer Swift2 Swift3,4,5... Tcl UnicodeC UnicodeC++ VB.NET VBScript VisualBasic6.0 VisualFoxPro XojoPlugin PowerShellExamples WebAPICategories ASN.1 AmazonEC2 AmazonGlacier AmazonS3 AmazonS3(new) AmazonSES AmazonSNS AmazonSQS Async AzureCloudStorage AzureServiceBus AzureTableService Base64 BouncedEmail Box CAdES CSR CSV Certificates Compression DKIM/DomainKey DSA Diffie-Hellman DigitalSignatures Dropbox DynamicsCRM EBICS ECC Ed25519 EmailObject Encryption FTP FileAccess Firebase GMailRESTAPI GMailSMTP/IMAP/POP Geolocation GoogleAPIs GoogleCalendar GoogleCloudSQL GoogleCloudStorage GoogleDrive GooglePhotos GoogleSheets GoogleTasks Gzip HTML-to-XML/Text HTTP HTTPMisc IMAP JSON JSONWebEncryption(JWE) JSONWebSignatures(JWS) JSONWebToken(JWT) JavaKeyStore(JKS) MHT/HTMLEmail MIME MSStorageProviders MicrosoftGraph NTLM OAuth1 OAuth2 OIDC Office365 OneDrive OpenSSL Outlook OutlookCalendar OutlookContact PDFSignatures PEM PFX/P12 PKCS11 POP3 PRNG REST RESTMisc RSA SCP SCard SFTP SMTP SSH SSHKey SSHTunnel ScMinidriver SharePoint Socket/SSL/TLS Spider Stream TarArchive Upload WebSocket XAdES XML XMLDigitalSignatures XMP Zip curl (PowerShell)ConvertaFilefromutf-8toANSI(suchasWindows-1252) Thisexampleistosatisfyaparticularuser'ssupportquestion: Ihaveafilethatcontainsthistext: OriginalfiletextConvertedusingnotepad TextCAFÉCAFÉ Hex434146c389434146c9 Theutf-8representationofthecharacterÉisthetwobytes0xC30x89.WhenNotepadisdisplayingtheutf-8file,itisintepretingthebytesasiftheyareANSI(1byteperchar),andthusitisshowingtheANSIcharfor0xC3(Ã)andtheANSIcharfor0x89(‰). AfterconvertingtoANSI,theÉisrepresentedbythesinglebyte0xC9. Chilkat.NETDownloads Chilkat.NETAssemblies ChilkatforMono Add-Type-Path"C:\chilkat\ChilkatDotNet47-9.5.0-x64\ChilkatDotNet47.dll" #ThisexampleassumestheChilkatAPItohavebeenpreviouslyunlocked. #SeeGlobalUnlockSampleforsamplecode. $charset=New-ObjectChilkat.Charset $charset.FromCharset="utf-8" $charset.ToCharset="ANSI" #Wecouldalternativelybemorespecificandsay"Windows-1252". #Theterm"ANSI"means--whatevercharacterencodingisdefinedastheANSI #encodingforthecomputer.InPoland,forexample,itwouldbethesingle-byte-per-char #usedtorepresntEasternEuropeanlanguagechars,whichisWindows-1250. $charset.ToCharset="Windows-1252" $success=$charset.ConvertFile("qa_data/txt/cafeUtf8.txt","qa_output/cafeAnsi.txt") if($success-ne$true){ $($charset.LastErrorText) exit } $("Success.") © 2000-2022ChilkatSoftware,Inc.AllRightsReserved.
延伸文章資訊
- 1ANSI Format - Micro Focus
- 2Changing source files encoding and some fun with PowerShell
The script detects encoding and saves file back in UTF-8. UPDATE: After I published the post I re...
- 3How to specify encoding when creating Powershell text file ...
I'm having an issue where the file is saved with encoding type Unicode - whereas I want the file ...
- 4How to convert multiple files encoded in UTF-8-BOM to ANSI?
I would like the output to be correct in both cases. If Powershell it's not the solution, what el...
- 5convert txt utf-8 to ansi - PowerShell - Spiceworks Community
I have a system generation csv files but as UTF-8. I want a way to automatically convert the file...