【问题标题】:Swift capitalise first letter of each word in string [duplicate]Swift将字符串中每个单词的首字母大写[重复]
【发布时间】:2017-08-30 17:07:23
【问题描述】:

我希望将字符串中每个单词的首字母大写。例如:

堆栈溢出 --> 堆栈溢出

堆栈溢出 --> 堆栈溢出

有谁知道在 swift 3 中实现这一点?

【问题讨论】:

    标签: ios swift


    【解决方案1】:

    在你的字符串上调用大写的函数,如下所示。

    var str = "hello, playground"
    str.capitalized
    print(str.capitalized)
    

    输出 Hello, Playground

    【讨论】:

      猜你喜欢
      • 2020-02-22
      • 2014-06-19
      • 1970-01-01
      • 2010-11-12
      • 2011-01-20
      • 2014-05-19
      • 2021-09-07
      • 2010-12-05
      相关资源
      最近更新 更多