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
(PureBasic) Implement Preprocessor #include with StringBuilderDemonstrates how to implement #include with a Chilkat StringBuilder.
IncludeFile "CkStringBuilder.pb" Procedure ChilkatExample() ; First build a string that has a preprocessor include sbSrc.i = CkStringBuilder::ckCreate() If sbSrc.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkStringBuilder::ckAppend(sbSrc,"1" + Chr(13) + Chr(10) + "2" + Chr(13) + Chr(10) + "3" + Chr(13) + Chr(10)) CkStringBuilder::ckAppend(sbSrc,"#include <qa_data/txt/helloWorld.txt>" + Chr(13) + Chr(10)) CkStringBuilder::ckAppend(sbSrc,"4" + Chr(13) + Chr(10) + "5" + Chr(13) + Chr(10)) Debug CkStringBuilder::ckGetAsString(sbSrc) ; sbSrc contains: ; 1 ; 2 ; 3 ; #include <qa_data/txt/helloWorld.txt> ; 4 ; 5 ; The qa_data/txt/helloWorld.txt file contains "Hello World!" filePath.s = CkStringBuilder::ckGetAfterBetween(sbSrc,"#include","<",">") If CkStringBuilder::ckLastMethodSuccess(sbSrc) <> 1 Debug "No #include's found." CkStringBuilder::ckDispose(sbSrc) ProcedureReturn EndIf Debug "filePath: " + filePath ; Load the contents of the filePath sbIncludeFile.i = CkStringBuilder::ckCreate() If sbIncludeFile.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkStringBuilder::ckLoadFile(sbIncludeFile,filePath,"utf-8") ; Replace the first occurrence of #include <...> line with the contents of the include file. CkStringBuilder::ckReplaceAllBetween(sbSrc,"#include",">",CkStringBuilder::ckGetAsString(sbIncludeFile),1) Debug CkStringBuilder::ckGetAsString(sbSrc) ; sbSrce now contains: ; 1 ; 2 ; 3 ; Hello World! ; 4 ; 5 CkStringBuilder::ckDispose(sbSrc) CkStringBuilder::ckDispose(sbIncludeFile) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.