Help us understand the problem. What is going on with this article?

NSStringのTips

More than 5 years have passed since last update.

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

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

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

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{
  // みつかった場合の処理
}
Sam
すまほあぷりえんじにーあ
http://d.hatena.ne.jp/samril/
lifull
日本最大級の不動産・住宅情報サイト「LIFULL HOME'S」を始め、人々の生活に寄り添う様々な情報サービス事業を展開しています。
https://lifull.com/
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
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  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
ユーザーは見つかりませんでした