根据Locale - Swift的大写所有字符串 [英] Uppercase All String According to Locale - Swift

查看:220
本文介绍了根据Locale - Swift的大写所有字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试根据'Locale'大写所有字符串,但它不起作用。

I'm trying to uppercase all string according to 'Locale' but it is not working.

var text = "istanbul, izmir"

println(text.uppercaseStringWithLocale(NSLocale.currentLocale())) 

在土耳其语中,我的大写是不是我。我的结果是伊斯坦布尔,IZMIR但它应该返回İSTANBUL,İZMİR。

In Turkish language the uppercase for i is İ not I. My Result is ISTANBUL, IZMIR but It should returns İSTANBUL, İZMİR.

请问我的位置在哪里问题?

Please where would be my issue?

推荐答案

NSLocale.currentLocale()是当前的语言环境在
设备的设置中选择。如果是en_US那么

NSLocale.currentLocale() is the locale which was selected in the Settings of the device. If that is "en_US" then

text.uppercaseStringWithLocale(NSLocale.currentLocale())

将使用英语语言规则,结果为ISTANBUL,IZMIR。

will use the english language rules and the result is "ISTANBUL, IZMIR".

您可以在设备设置中选择土耳其语,或者
明确指定土耳其语区域:

You can either select the turkish language in the device settings, or specify the turkish locale explicitly:

let text = "istanbul, izmir"
text.uppercaseStringWithLocale(NSLocale(localeIdentifier: "tr"))
// İSTANBUL, İZMİR

Swift 3:

text.uppercased(with: Locale(identifier: "tr"))

这篇关于根据Locale - Swift的大写所有字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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