How to append a character to a string in Swift?

后端 未结 8 1771
长情又很酷
长情又很酷 2021-01-01 10:15

This used to work in Xcode 6: Beta 5. Now I\'m getting a compilation error in Beta 6.

for aCharacter: Character in aString {
    var str: String = \"\"
    v         


        
相关标签:
8条回答
  • 2021-01-01 10:37
     let original:String = "Hello"
     var firstCha = original[original.startIndex...original.startIndex]
    
     var str = "123456789"
     let x = (str as NSString).substringWithRange(NSMakeRange(0, 4))
    
     var appendString1 = "\(firstCha)\(x)" as String!
     // final name
     var namestr = "yogesh"
     var appendString2 = "\(namestr) (\(appendString1))" as String!*
    
    0 讨论(0)
  • 2021-01-01 10:40

    Another possible option is

    var s: String = ""
    var c: Character = "c"
    s += "\(c)"
    
    0 讨论(0)
提交回复
热议问题