Sample code for 30+ languages & platforms
Swift

HTML Entity Encode and Decode in StringBuilder

Demonstrates HTML encoding and decoding the contents of a StringBuilder.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    let sb = CkoStringBuilder()!

    var s: String? = "< é ü ç Ω Hello & World ✓ >"
    sb.append(value: s)

    sb.encode(encoding: "html", charset: "utf-8")
    print("\(sb.getAsString()!)")

    // Output:
    // < &eacute; &uuml; &ccedil; &ohm; Hello & World &check; >

    // To decode:
    sb.decode(encoding: "html", charset: "utf-8")
    print("\(sb.getAsString()!)")

    // Output:
    // < é ü ç Ω Hello & World ✓ >

}