Sample code for 30+ languages & platforms
Swift

Convert HTML to Plain Text

Demonstrates how to convert HTML to plain text.

Chilkat Swift Downloads

Swift

func chilkatTest() {
    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    let h2t = CkoHtmlToText()!

    var html: String? = h2t.readFile(toString: "c:/temp/test.html", srcCharset: "utf-8")
    if h2t.lastMethodSuccess == false {
        print("\(h2t.lastErrorText!)")
        return
    }

    var plainText: String? = h2t.toText(html: html)
    if h2t.lastMethodSuccess == false {
        print("\(h2t.lastErrorText!)")
        return
    }

    print("\(plainText!)")

}