Sample code for 30+ languages & platforms
Swift

StringBuilder GetNth

Demonstrates the GetNth method.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    // The GetNth method is handy for getting parts from delimited strings.
    // For example:

    let sb = CkoStringBuilder()!
    sb.append(value: "red,blue,\"green,purple\",,yellow")

    var delimiterChar: String? = ","
    var exceptDoubleQuoted: Bool = true
    var exceptEscaped: Bool = true

    // Prints "[red]"
    print("[\(sb.getNth(index: 0, delimiterChar: delimiterChar, exceptDoubleQuoted: exceptDoubleQuoted, exceptEscaped: exceptEscaped)!)]")

    // Prints "[blue]"
    print("[\(sb.getNth(index: 1, delimiterChar: delimiterChar, exceptDoubleQuoted: exceptDoubleQuoted, exceptEscaped: exceptEscaped)!)]")

    // Prints "[green,purple]"
    print("[\(sb.getNth(index: 2, delimiterChar: delimiterChar, exceptDoubleQuoted: exceptDoubleQuoted, exceptEscaped: exceptEscaped)!)]")

    // Prints "[]"
    print("[\(sb.getNth(index: 3, delimiterChar: delimiterChar, exceptDoubleQuoted: exceptDoubleQuoted, exceptEscaped: exceptEscaped)!)]")

    // Prints "[yellow]"
    print("[\(sb.getNth(index: 4, delimiterChar: delimiterChar, exceptDoubleQuoted: exceptDoubleQuoted, exceptEscaped: exceptEscaped)!)]")

    // Prints "[]"
    print("[\(sb.getNth(index: 5, delimiterChar: delimiterChar, exceptDoubleQuoted: exceptDoubleQuoted, exceptEscaped: exceptEscaped)!)]")

}