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
(PowerBuilder) Extract data:image/png;base64 from HTMLDemonstrates how to extract base64 image data from HTMl and save to files.
integer li_rc oleobject loo_Sb oleobject loo_Bd oleobject loo_SbFilename integer li_Index integer li_Success integer li_MayHaveMore string ls_SBase64 integer li_Count loo_Sb = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_Sb.ConnectToNewObject("Chilkat.StringBuilder") if li_rc < 0 then destroy loo_Sb MessageBox("Error","Connecting to COM object failed") return end if loo_Bd = create oleobject // Use "Chilkat_9_5_0.BinData" for versions of Chilkat < 10.0.0 li_rc = loo_Bd.ConnectToNewObject("Chilkat.BinData") loo_SbFilename = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbFilename.ConnectToNewObject("Chilkat.StringBuilder") li_Index = 1 li_Success = loo_Sb.LoadFile("qa_data/html/oresp body.txt","utf-8") // Assume success. Write-Debug "length = " + string(loo_Sb.Length) li_MayHaveMore = 1 do while li_MayHaveMore = 1 // Get the base64 between the 1st occurrence "data:image/png;base64," and "'" ls_SBase64 = loo_Sb.GetBetween("data:image/png;base64,","'") // If nothing is found, then we'll exit the loop because there are no more. li_MayHaveMore = loo_Sb.LastMethodSuccess if loo_Sb.LastMethodSuccess = 1 then // Found something. // Load into bd and save. li_Success = loo_Bd.LoadEncoded(ls_SBase64,"base64") loo_SbFilename.SetString("qa_output/png_") loo_SbFilename.AppendInt(li_Index) loo_SbFilename.Append(".png") loo_Bd.WriteFile(loo_SbFilename.GetAsString()) // Replace "data:image/png;base64" with "data:image-png;base64" so the next iteration finds the next occurrence. loo_Sb.ReplaceFirst("data:image/png;base64","data:image-png;base64") end if li_Index = li_Index + 1 loop // Restore our replacements.. li_Count = loo_Sb.Replace("data:image-png;base64","data:image/png;base64") Write-Debug "All done." destroy loo_Sb destroy loo_Bd destroy loo_SbFilename |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.