文字列があり、「#」で始まり「。」で終わる単語(タグ)を検索したい。または「」または 『』私はこのオンラインを見つけましたが、ため制限されている: - (より多くの言葉がありますが) あなたは、文字列内の単一の単語を見つけることができます - 『RangeOfString』複数の選択肢文字列内のタグを検索する
NSString *stringText = @"test #hello #world";
NSString *result = nil;
// Determine "#"
NSRange hashRange = [stringText rangeOfString:@"#" options:NSCaseInsensitiveSearch];
if (hashRange.location != NSNotFound)
{
// Determine " " location according to "#" location
NSRange endHashRange;
endHashRange.location = hashRange.length + hashRange.location;
endHashRange.length = [stringText length] - endHashRange.location;
endHashRange = [stringText rangeOfString:@" " options:NSCaseInsensitiveSearch range:endHashRange];
if (endHashRange.location != NSNotFound)
{
// Tags found: retrieve string between them
hashRange.location += hashRange.length;
hashRange.length = endHashRange.location - hashRange.location;
result = [stringText substringWithRange:hashRange];
}
}
を許可しません。
あなたはどうすればいいですか?
ありがとうございました!
ありがとうございますが、私はマッチから外挿することはできません。彼は正しい数の単語を返しますが、単語ではなくコードを返します。 – Vins
@Vins編集を見て、これは 'matches'配列から実際の文字列を得る方法を明確にするはずです。 – dasblinkenlight
うわー!どうもありがとう! – Vins