swift – 将unichar转换为String?

前端之家收集整理的这篇文章主要介绍了swift – 将unichar转换为String?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我从NSString的实例方法characterAtIndex(Int)返回一个unichar类型,我想将它与 Swift类型的String进行比较.是否有捷径可寻?
var str = "#ffffff"
var unichar = (str as NSString).characterAtIndex(0)
var unicharString = // Perform magic
var containsHash = unicharString == "#" // Should return `true`

谢谢

var str:String = "#ffffff"
var unichar = str[str.startIndex]
var unicharString = "\(unichar)"
var containsHash = unicharString == "#"
原文链接:https://www.f2er.com/swift/318759.html

猜你在找的Swift相关文章