Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
8
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

@Sam

NSStringのTips

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

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

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

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{
  // みつかった場合の処理
}
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
8
Help us understand the problem. What are the problem?