1

この種の値を持つ文字列があります/finocchi$FINOCCHamelo

ここで、単語のこの部分のみを含む新しい文字列が必要ですFINOCCHamelo

私はこれを試しました:

NSString * newString = [item.label stringByReplacingOccurrencesOfString:@"$" withString:@""];

しかし、$ を空白文字に変更しているため、正しくありません。$ の後に文字列をフィルタリングする必要があります。どうすればよいですか?

4

1 に答える 1

1

Assuming in all the case you have only one $ in your string and you need the value after $.

NSArray *brokenStrings = [item.label componentsSeparatedByString:@"$"];
NSString *filteredString = [brokenStrings objectAtIndex:1];

There are a lot more ways to do this: You can opt any one from these methods, or dozen other methods are available in NSString.

– componentsSeparatedByString:
– substringFromIndex:
- rangeOfString:
– stringByTrimmingCharactersInSet:
于 2012-11-16T14:04:59.303 に答える