Skip to content

Instantly share code, notes, and snippets.

@kichiemon
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

  • Save kichiemon/5c0cf54f5b97758a8b1b to your computer and use it in GitHub Desktop.

Select an option

Save kichiemon/5c0cf54f5b97758a8b1b to your computer and use it in GitHub Desktop.
[Swift]Stringから1文字目を取り出す方法メモ ref: http://qiita.com/iKichiemon/items/4736110a80dab10177ea
let str: String = "HelloWorld"
let str: String = "HelloWorld"
let nsStr: NSString = str as NSString
let firstChar: String = nsStr.substringToIndex(1)
println(firstCha) /// "H"
var str = "Hello, playground"
//1文字目(0文字目)
str[str.startIndex]
//n文字目
let n = 5
str[advance(str.startIndex, n)]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment