Sample code for 30+ languages & platforms
Swift

StringBuilder GetEncoded

Demonstrates the Chilkat StringBuilder GetEncoded method.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    var s: String? = "The quick brown fox jumps over the lazy dog"

    let sb = CkoStringBuilder()!

    sb.append(value: s)

    // output: The quick brown fox jumps over the lazy dog
    print("\(sb.getAsString()!)")

    // Get the string encoded to base64, without changing the contents of sb.
    // output: VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wcyBvdmVyIHRoZSBsYXp5IGRvZw==
    print("\(sb.getEncoded(encoding: "base64", charset: "utf-8")!)")

    // The contents of sb are not changed..
    // output: The quick brown fox jumps over the lazy dog
    print("\(sb.getAsString()!)")

}