8
8

More than 5 years have passed since last update.

NSStringのTips

Last updated at Posted at 2014-02-07

たまに忘れるのでメモ、どんどん増やすかも

区切り文字で配列に変換する &その逆

・配列から文字列へセパレータで区切りつつ連結させる

NSArray *arr = @[@"Hello", @"World", @"!"];
NSString *str = [arr componentsJoinedByString:@","];
// Hello,World,!

・配列から文字列へセパレータで区切りつつ連結させる

NSString *str = @"Hello,World,!";
NSArray *arr = [str componentsSeparatedByString:@","];
// @{@"Hello", @"World", @"!"}

文字列検索

・文字列の中に、対象の文字列が存在するか確認

NSString *str = @"Hello World!";
NSRange searchResult = [str rangeOfString:@"World"];
// location=6, length=5

if(searchResult.location == NSNotFound) {
  // みつからない場合の処理
}else{
  // みつかった場合の処理
}
8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8