我是靠谱客的博主 花痴羽毛,最近开发中收集的这篇文章主要介绍swift string转为html,将字符串编码为HTML字符串Swift 3,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

func testEscape()throws {

let text = "Hello &<> Å å π 新 there ¾ © »"

let escapedAscii = Entities.escape(text, OutputSettings().encoder(String.Encoding.ascii).escapeMode(Entities.EscapeMode.base))

let escapedAsciiFull = Entities.escape(text, OutputSettings().charset(String.Encoding.ascii).escapeMode(Entities.EscapeMode.extended))

let escapedAsciiXhtml = Entities.escape(text, OutputSettings().charset(String.Encoding.ascii).escapeMode(Entities.EscapeMode.xhtml))

let escapedUtfFull = Entities.escape(text, OutputSettings().charset(String.Encoding.utf8).escapeMode(Entities.EscapeMode.extended))

let escapedUtfMin = Entities.escape(text, OutputSettings().charset(String.Encoding.utf8).escapeMode(Entities.EscapeMode.xhtml))

XCTAssertEqual("Hello &<> Å å π 新 there ¾ © »", escapedAscii)

XCTAssertEqual("Hello &<> &angst; å π 新 there ¾ © »", escapedAsciiFull)

XCTAssertEqual("Hello &<> Å å π 新 there ¾ © »", escapedAsciiXhtml)

XCTAssertEqual("Hello &<> Å å π 新 there ¾ © »", escapedUtfFull)

XCTAssertEqual("Hello &<> Å å π 新 there ¾ © »", escapedUtfMin)

// odd that it's defined as aring in base but angst in full

// round trip

XCTAssertEqual(text, try Entities.unescape(escapedAscii))

XCTAssertEqual(text, try Entities.unescape(escapedAsciiFull))

XCTAssertEqual(text, try Entities.unescape(escapedAsciiXhtml))

XCTAssertEqual(text, try Entities.unescape(escapedUtfFull))

XCTAssertEqual(text, try Entities.unescape(escapedUtfMin))

}

最后

以上就是花痴羽毛为你收集整理的swift string转为html,将字符串编码为HTML字符串Swift 3的全部内容,希望文章能够帮你解决swift string转为html,将字符串编码为HTML字符串Swift 3所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(49)

评论列表共有 0 条评论

立即
投稿
返回
顶部