PowerShell Convert a File from utf-8 to ANSI (such as ...

文章推薦指數: 80 %
投票人數:10人

(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.



請為這篇文章評分?