Sample code for 30+ languages & platforms
B4X

StringBuilder SetNth

Demonstrates the SetNth method.

Chilkat B4X Downloads

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

Dim sb As ChilkatStringBuilder
sb.Initialize
sb.Append("red,blue," & Chr(34) & "green,purple" & Chr(34) & ",,yellow")

Dim delimiterChar As String = ","
Dim exceptDoubleQuoted As Boolean = True
Dim exceptEscaped As Boolean = True

sb.SetNth(2, "magenta", delimiterChar, exceptDoubleQuoted, exceptEscaped)
'  Prints "red,blue,magenta,,yellow"
Log(sb.GetAsString)

sb.SetNth(3, "orange", delimiterChar, exceptDoubleQuoted, exceptEscaped)
'  Prints "red,blue,magenta,orange,yellow"
Log(sb.GetAsString)


'  What happens if we start with an empty string?
sb.Clear

sb.SetNth(2, "apple", delimiterChar, exceptDoubleQuoted, exceptEscaped)
'  Prints ",,apple"
Log(sb.GetAsString)

sb.SetNth(0, "orange", delimiterChar, exceptDoubleQuoted, exceptEscaped)
'  Prints "orange,,apple"
Log(sb.GetAsString)

sb.SetNth(1, "banana", delimiterChar, exceptDoubleQuoted, exceptEscaped)
'  Prints "orange,banana,apple"
Log(sb.GetAsString)