Swift学习笔记·String

2016-03-08  本文已影响0人  JokerAIF

初学 String 比较关注 String 的基本使用方法

let greeting = "Guten Tag!"  
greeting[greeting.startIndex]  
//G
greeting[greeting.endIndex.predecessor()]  
//!
greeting[greeting.startIndex.successor()]  
//u
let index = greeting.startIndex.advancedBy(7)  
//a
greeting[index]  
//输出 a

     使用for-in循环来遍历String的:

for index in greeting.characters.indices {  
    print("\(greeting[index])", terminator: " ")
}
///prints "G u t e n  T a g !"
上一篇下一篇

猜你喜欢

热点阅读