如何将 NSAttributedString 中的字符大小写更改为大写
我想将包含 RTFD 的 NSAttributedString 转换为大写,而不丢失现有字符和图形的属性。
谢谢,
I want to convert NSAttributedString containing RTFD to uppercase without losing attributes of existing characters and graphics.
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑:
@fluidsonic 是正确的,原始代码不正确。下面是 Swift 的更新版本,它将每个属性范围中的文本替换为该范围内字符串的大写版本。
原答案:
作用:
EDIT:
@fluidsonic Is correct that the original code is incorrect. Below is an updated version in Swift, that replaces the text in each attribute range with an uppercased version of the string in that range.
Original answer:
What this does:
NSString
method.当您大写德语“ß”字符时,它会变成“SS”;因此范围发生变化。这可能会导致接受的答案崩溃。以下是我针对此案例的建议:
When you uppercase German "ß" character, it becomes "SS"; therefore the range changes. This might cause crash in the accepted answer. Here's my proposal to cover this case as well: