Last active
October 31, 2015 12:54
-
-
Save KentarouKanno/7c2a4e6da7d6a73e055b to your computer and use it in GitHub Desktop.
join separate components
This file contains 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
// 配列を区切り文字で連結 | |
(Obj-C) | |
NSArray *array = @[@"1",@"2",@"3",@"4",@"5"]; | |
NSString *joinedString = [array componentsJoinedByString:@","]; | |
(Swift) | |
let joinedString = ["1", "2", "3", "4", "5"].joinWithSeparator(",") | |
//=> "1,2,3,4,5" | |
// 文字列を指定文字で配列に分割 | |
(Obj-C) | |
NSString *str = @"1,2,3,4,5"; | |
NSArray *separatedString = [str componentsSeparatedByString:@","]; | |
(Swift) | |
let separatedString = "1,2,3,4,5".componentsSeparatedByString(",") | |
//=> ["1", "2", "3", "4", "5"] | |
or | |
extension String : CollectionType {} | |
let separatedString = "1,2,3,4,5".split {$0 == ","} | |
//=> ["1", "2", "3", "4", "5"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment