Search code examples
cocoansstringstring-matching

Check whether NSString contains a comma (,)


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?


Solution

  • 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");
    }