Swift switch char{ case "\u{e2}: [英] Swift switch char{ case "\u{e2}:

查看:26
本文介绍了Swift switch char{ case "\u{e2}:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

let splitLines = line.split(separator: "\u{e2}")

case "\u{e2}":
                print("FoundBadReturn")

let newText = text.replacingOccurrences(of: "\u{e2}", with: "\n")

我正在处理 UITextView 中的 RTF 文档.我正在尝试使用 \n 更改包含 \u{e2} 字符的字符串这些行似乎都不适用于字符串

I'm working with a RTF Document in UITextView. I'm trying to change Strings that contain \u{e2} char with \n None of these lines seem to work against Strings

推荐答案

调试器打印具有误导性.字符是 "\u{2028}" 'Line Separator' 而不是 "\u{e2}".调试器这样做是因为 0xE2 是 UTF8 中该字符的第一个字节,它隐藏了其余部分.如果您尝试在 "\u{2028}" 上执行操作(删除、替换、包含...),它们将起作用.

The debugger print is misleading. The character is "\u{2028}" 'Line Separator' rather than "\u{e2}". The debugger does this because 0xE2 is the first byte of that character in UTF8, and it hides the rest. If you instead try to perform your operations (delete, replace, contains...) on "\u{2028}", they will work.

这篇关于Swift switch char{ case "\u{e2}:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆