Sample code for 30+ languages & platforms
PowerBuilder

Implement Preprocessor #include with StringBuilder

Demonstrates how to implement #include with a Chilkat StringBuilder.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
oleobject loo_SbSrc
string ls_FilePath
oleobject loo_SbIncludeFile

//  First build a string that has a preprocessor include
loo_SbSrc = create oleobject
li_rc = loo_SbSrc.ConnectToNewObject("Chilkat.StringBuilder")
if li_rc < 0 then
    destroy loo_SbSrc
    MessageBox("Error","Connecting to COM object failed")
    return
end if
loo_SbSrc.Append("1~r~n2~r~n3~r~n")
loo_SbSrc.Append("#include <qa_data/txt/helloWorld.txt>~r~n")
loo_SbSrc.Append("4~r~n5~r~n")

Write-Debug loo_SbSrc.GetAsString()

//  sbSrc contains:
//  	1
//  	2
//  	3
//  	#include <qa_data/txt/helloWorld.txt>
//  	4
//  	5

//  The qa_data/txt/helloWorld.txt file contains "Hello World!"

ls_FilePath = loo_SbSrc.GetAfterBetween("#include","<",">")
if loo_SbSrc.LastMethodSuccess <> 1 then
    Write-Debug "No #include's found."
    destroy loo_SbSrc
    return
end if

Write-Debug "filePath: " + ls_FilePath

//  Load the contents of the filePath
loo_SbIncludeFile = create oleobject
li_rc = loo_SbIncludeFile.ConnectToNewObject("Chilkat.StringBuilder")

loo_SbIncludeFile.LoadFile(ls_FilePath,"utf-8")

//  Replace the first occurrence of #include <...> line with the contents of the include file.
loo_SbSrc.ReplaceAllBetween("#include",">",loo_SbIncludeFile.GetAsString(),1)

Write-Debug loo_SbSrc.GetAsString()

//  sbSrce now contains:
//  	1
//  	2
//  	3
//  	Hello World!
//  	4
//  	5


destroy loo_SbSrc
destroy loo_SbIncludeFile