Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(DataFlex) StringBuilder to Bytes (in BinData)Demonstrates converting a string to bytes of a particular character encoding. Note: This example requires Chilkat v9.5.0.64 or later.
Use ChilkatAx-win32.pkg Procedure Test Handle hoHttp Variant vSbJson Handle hoSbJson Boolean iSuccess Variant vSbGreek Handle hoSbGreek Handle hoJson String sGreekAlphabet Handle hoBinWindows1253 Handle hoBinUtf8 Handle hoBinUtf16 String sTemp1 // This initial step gets string data to be used in this example from a live URL. // It assumes Chilkat HTTP API to have been previously unlocked. // See Global Unlock Sample for sample code. Get Create (RefClass(cComChilkatHttp)) To hoHttp If (Not(IsComObjectCreated(hoHttp))) Begin Send CreateComObject of hoHttp End Set ComVerboseLogging Of hoHttp To True Get Create (RefClass(cComChilkatStringBuilder)) To hoSbJson If (Not(IsComObjectCreated(hoSbJson))) Begin Send CreateComObject of hoSbJson End Get pvComObject of hoSbJson to vSbJson Get ComQuickGetSb Of hoHttp "https://www.chilkatsoft.com/exampleData/greekAlphabet.json" vSbJson To iSuccess If (Not iSuccess) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get Create (RefClass(cComChilkatStringBuilder)) To hoSbGreek If (Not(IsComObjectCreated(hoSbGreek))) Begin Send CreateComObject of hoSbGreek End Get Create (RefClass(cComChilkatJsonObject)) To hoJson If (Not(IsComObjectCreated(hoJson))) Begin Send CreateComObject of hoJson End Get pvComObject of hoSbJson to vSbJson Get ComLoadSb Of hoJson vSbJson To iSuccess // The JSON contains this: // { // "greekAlphabet": "Α α Β β Γ γ Δ δ Ε ε Ζ ζ Η η Θ θ Ι ι Κ κ Λ λ Μ μ Ν ν Ξ ξ Ο ο Π π Ρ ρ Σ σ ς Τ τ Υ υ Φ φ Χ χ Ψ ψ Ω ω" // } Get ComStringOf Of hoJson "greekAlphabet" To sGreekAlphabet Get ComAppend Of hoSbGreek sGreekAlphabet To iSuccess // Append the Windows-1253 represention of the string.. // In this encoding, each Greek char is one byte per char. Get Create (RefClass(cComChilkatBinData)) To hoBinWindows1253 If (Not(IsComObjectCreated(hoBinWindows1253))) Begin Send CreateComObject of hoBinWindows1253 End Get pvComObject of hoSbGreek to vSbGreek Get ComAppendSb Of hoBinWindows1253 vSbGreek "windows-1253" To iSuccess // Save to a Windows-1253 text file: Get ComWriteFile Of hoBinWindows1253 "qa_output/greek_win1253.txt" To iSuccess // Show the bytes in the quoted-printable format so we can easily see the Windows-1253 byte values. Get ComGetEncoded Of hoBinWindows1253 "qp" To sTemp1 Showln sTemp1 Showln "--------------------------------" // The result is shown here: // =C1 =E1 =C2 =E2 =C3 =E3 =C4 =E4 =C5 =E5 =C6 =E6 =C7 =E7 =C8 =E8 =C9 =E9 =CA= // =EA =CB =EB =CC =EC =CD =ED =CE =EE =CF =EF =D0 =F0 =D1 =F1 =D3 =F3 =F2 = // =D4 =F4 =D5 =F5 =D6 =F6 =D7 =F7 =D8 =F8 =D9 =F9 // Append the utf-8 represention of the string.. Get Create (RefClass(cComChilkatBinData)) To hoBinUtf8 If (Not(IsComObjectCreated(hoBinUtf8))) Begin Send CreateComObject of hoBinUtf8 End Get ComAppendBom Of hoBinUtf8 "utf-8" To iSuccess Get pvComObject of hoSbGreek to vSbGreek Get ComAppendSb Of hoBinUtf8 vSbGreek "utf-8" To iSuccess // Save to a utf-8 text file: Get ComWriteFile Of hoBinUtf8 "qa_output/greek_utf8.txt" To iSuccess // Show the bytes in the quoted-printable format so we can easily see the utf-8 char representations. Get ComGetEncoded Of hoBinUtf8 "qp" To sTemp1 Showln sTemp1 Showln "--------------------------------" // These are the utf-8 bytes shown in quoted-printable encoding: // =EF=BB=BF=CE=91 =CE=B1 =CE=92 =CE=B2 =CE=93 =CE=B3 =CE=94 =CE=B4 =CE=95 =CE= // =B5 =CE=96 =CE=B6 =CE=97 =CE=B7 =CE=98 =CE=B8 =CE=99 =CE=B9 =CE=9A =CE=BA = // =CE=9B =CE=BB =CE=9C =CE=BC =CE=9D =CE=BD =CE=9E =CE=BE =CE=9F =CE=BF =CE= // =A0 =CF=80 =CE=A1 =CF=81 =CE=A3 =CF=83 =CF=82 =CE=A4 =CF=84 =CE=A5 =CF=85 = // =CE=A6 =CF=86 =CE=A7 =CF=87 =CE=A8 =CF=88 =CE=A9 =CF=89 // Append the utf-16 (little endian) represention of the string.. Get Create (RefClass(cComChilkatBinData)) To hoBinUtf16 If (Not(IsComObjectCreated(hoBinUtf16))) Begin Send CreateComObject of hoBinUtf16 End Get ComAppendBom Of hoBinUtf16 "utf-16" To iSuccess Get pvComObject of hoSbGreek to vSbGreek Get ComAppendSb Of hoBinUtf16 vSbGreek "utf-16" To iSuccess // Save to a utf-16 text file: Get ComWriteFile Of hoBinUtf16 "qa_output/greek_utf16.txt" To iSuccess Get ComGetEncoded Of hoBinUtf16 "qp" To sTemp1 Showln sTemp1 // These are the utf-16 bytes shown in quoted-printable encoding: // =FF=FE=91=03 =00=B1=03 =00=92=03 =00=B2=03 =00=93=03 =00=B3=03 =00=94=03 = // =00=B4=03 =00=95=03 =00=B5=03 =00=96=03 =00=B6=03 =00=97=03 =00=B7=03 =00= // =98=03 =00=B8=03 =00=99=03 =00=B9=03 =00=9A=03 =00=BA=03 =00=9B=03 =00=BB= // =03 =00=9C=03 =00=BC=03 =00=9D=03 =00=BD=03 =00=9E=03 =00=BE=03 =00=9F=03 = // =00=BF=03 =00=A0=03 =00=C0=03 =00=A1=03 =00=C1=03 =00=A3=03 =00=C3=03 =00= // =C2=03 =00=A4=03 =00=C4=03 =00=A5=03 =00=C5=03 =00=A6=03 =00=C6=03 =00=A7= // =03 =00=C7=03 =00=A8=03 =00=C8=03 =00=A9=03 =00=C9=03 End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.