这是我到目前为止所尝试的
let cap = [description.substringToIndex(advance(0,1))] as String description = cap.uppercaseString + description.substringFromIndex(1)
它给了我:类型’String.Index’不符合协议’IntegerliteralConvertible’
我试过了
func cAPItalizedStringWithLocale(locale:0) -> String
但我无法弄清楚如何让它发挥作用.
有任何想法吗?
import Foundation// A lowercase stringlet description = "the quick brown fox jumps over the lazy dog."// The start index is the first letterlet first = description.startIndex// The rest of the string goes from the position after the first letter// to the end.let rest = advance(first,1)..<description.endindex// glue these two ranges together,with the first uppercased,and you'll// get the result you want. Note that I'm using description[first...first]// to get the first letter because I want a String,not a Character,which// is what you'd get with description[first].let cAPItalised = description[first...first].uppercaseString + description[rest]// Result: "The quick brown fox jumps over the lazy dog."
您可能希望确保在开始之前句子中至少有一个字符,否则您将在尝试将索引超出字符串末尾时遇到运行时错误.
总结以上是内存溢出为你收集整理的资本化第一句话(斯威夫特)全部内容,希望文章能够帮你解决资本化第一句话(斯威夫特)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)