4

I have string separated by a comma. First I want to check whether or not the string contains a comma. In my app the string looks like this:

NSString *str=@"1,2,3";    

How to check whether or not it contains a comma?

BSMP
  • 4,596
  • 8
  • 33
  • 44
Pradhyuman sinh
  • 3,936
  • 1
  • 23
  • 38
  • Possible duplicate of [This question](http://stackoverflow.com/questions/3293499/detecting-if-an-nsstring-contains) – Vreality Dec 11 '12 at 13:44

1 Answers1

1

I solved my problem by using following code:

NSString *str=@"1,2,3";
NSArray *result=[str componentsSeparatedByString:@","];
if([result count]!=0)
{
    NSLog(@"String contains comma");
}
Pradhyuman sinh
  • 3,936
  • 1
  • 23
  • 38