在Swift中使用Umlaut转换字符串

时间:2015-01-18 22:32:26

标签: ios swift

我有一个文本字段输入,返回如下字符串:

let name = "B\U00f6se"

如何转换变音符号,以便\ U00f6(和任何其他特殊字符)被替换为正确的等效字符:

name = "Böse";

感谢您的帮助!

//的Seb

2 个答案:

答案 0 :(得分:0)

descriptionNSArray的{​​{1}}方法使用NSDictionary 所有非ASCII字符的转义序列。

在SwiftForms附带的Xcode示例项目中,提交方法 将此描述显示给用户:

\Unnnn

效果就是你看到了例如

func submit(_: UIBarButtonItem!) {

    let message = self.form.formValues().description
    let alert: UIAlertView = UIAlertView(title: "Form output", message: message, delegate: nil, cancelButtonTitle: "OK")
    alert.show()
}

lastName = "B\U00f6se"; 方法仅适用于调试或记录。 你应该做的是枚举所有的键和值:

description

会告诉你

for (key, value) in self.form.formValues() {
    println("\(key) = \(value)")
}

或检索您感兴趣的表单值:

lastName = Böse

答案 1 :(得分:0)

有一种更简单的方法。

let name = "B\u{00f6}se"
pinrtln(name)

有关详细信息,请查看this entry