Sample code for 30+ languages & platforms
PowerBuilder

StringBuilder SetNth

Demonstrates the SetNth method.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
oleobject loo_Sb
string ls_DelimiterChar
integer li_ExceptDoubleQuoted
integer li_ExceptEscaped

// The SetNth method is handy for setting a part of a delimited string.
// For example:

loo_Sb = create oleobject
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_Sb.Append("red,blue,~"green,purple~",,yellow")

ls_DelimiterChar = ","
li_ExceptDoubleQuoted = 1
li_ExceptEscaped = 1

loo_Sb.SetNth(2,"magenta",ls_DelimiterChar,li_ExceptDoubleQuoted,li_ExceptEscaped)
// Prints "red,blue,magenta,,yellow"
Write-Debug loo_Sb.GetAsString()

loo_Sb.SetNth(3,"orange",ls_DelimiterChar,li_ExceptDoubleQuoted,li_ExceptEscaped)
// Prints "red,blue,magenta,orange,yellow"
Write-Debug loo_Sb.GetAsString()

// What happens if we start with an empty string?
loo_Sb.Clear()

loo_Sb.SetNth(2,"apple",ls_DelimiterChar,li_ExceptDoubleQuoted,li_ExceptEscaped)
// Prints ",,apple"
Write-Debug loo_Sb.GetAsString()

loo_Sb.SetNth(0,"orange",ls_DelimiterChar,li_ExceptDoubleQuoted,li_ExceptEscaped)
// Prints "orange,,apple"
Write-Debug loo_Sb.GetAsString()

loo_Sb.SetNth(1,"banana",ls_DelimiterChar,li_ExceptDoubleQuoted,li_ExceptEscaped)
// Prints "orange,banana,apple"
Write-Debug loo_Sb.GetAsString()


destroy loo_Sb