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.
延伸文章資訊
- 1File encoding - Mastering Windows PowerShell Scripting
File encoding Windows editors, including ISE, tend to save files using what is commonly known as ...
- 2How to save command output to file using Command Prompt or ...
- 3Convert text file to ANSI format - powershell - Stack Overflow
The following solved my problem: Out-File 'file.txt' -Append -Encoding Ascii. This enabled me to ...
- 4convert 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...
- 5PowerShell 輸出結果編碼問題 - 黑暗執行緒
Do-Something.ps1 > output.txt 存檔是用ANSI/BIG5 編碼,但事實不然。 ... 其編碼Export-PSSession 用UTF8(含BOM) New-Ite...