Last active
August 29, 2015 14:10
-
-
Save kichiemon/5c0cf54f5b97758a8b1b to your computer and use it in GitHub Desktop.
[Swift]Stringから1文字目を取り出す方法メモ ref: http://qiita.com/iKichiemon/items/4736110a80dab10177ea
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let str: String = "HelloWorld" | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let str: String = "HelloWorld" | |
| let nsStr: NSString = str as NSString | |
| let firstChar: String = nsStr.substringToIndex(1) | |
| println(firstCha) /// "H" | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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