如何在swift 4中阻止html编码将双空格替换为单空格

如何在swift 4中阻止html编码将双空格替换为单空格,html,swift,character-encoding,whitespace,Html,Swift,Character Encoding,Whitespace,我有以下字符串: tweetContent = "Hello World!" 如你所见,它有两个空格。这就是我想要的 现在我需要对该字符串进行编码,以检查HTML字符,例如&。我使用以下代码行执行此操作: let attributedString = try? NSMutableAttributedString( data: tweetContent.data(using: String.Encoding.unicode, allowLossyConve

我有以下字符串:

tweetContent = "Hello  World!"
如你所见,它有两个空格。这就是我想要的

现在我需要对该字符串进行编码,以检查HTML字符,例如
&。我使用以下代码行执行此操作:

let attributedString = try? NSMutableAttributedString(
                data: tweetContent.data(using: String.Encoding.unicode, allowLossyConversion: true)!,
                options: [NSAttributedString.DocumentReadingOptionKey.documentType: NSAttributedString.DocumentType.html],
                documentAttributes: nil)

问题是,它将字符串中的双空格替换为单个空格。这不是我想要的。如何阻止它这样做?

无论如何,在HTML中,双空格将显示为单个空格。问题是,我使用字符计数为NSAttributedText的文本着色。