如何使用Swift iOS大写字符串中的每个单词 [英] How to capitalize each word in a string using Swift iOS

查看:102
本文介绍了如何使用Swift iOS大写字符串中的每个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一个函数来大写字符串中的每个单词或这是一个手动过程?

Is there a function to capitalize each word in a string or is this a manual process?

例如bob很高
而且我想要Bob Is Tall

For e.g. "bob is tall" And I would like "Bob Is Tall"

肯定有一些东西,我找到的Swift IOS答案似乎都没有覆盖这个。

Surely there is something and none of the Swift IOS answers I have found seemed to cover this.

推荐答案

您在寻找 capitalizedString


讨论

每个单词中第一个字符的字符串更改为相应的大写字母值,并将所有剩余字符设置为相应的小写值。

Discussion
A string with the first character in each word changed to its corresponding uppercase value, and all remaining characters set to their corresponding lowercase values.

和/或 capitalizedStringWithLocale(_: )

使用指定的语言环境返回接收者的大写表示。

Returns a capitalized representation of the receiver using the specified locale.

对于提供给用户的字符串,传递当前语言环境([NSLocale currentLocale ])。要使用系统区域设置,请传递nil。

For strings presented to users, pass the current locale ([NSLocale currentLocale]). To use the system locale, pass nil.

这篇关于如何使用Swift iOS大写字符串中的每个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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