iPhone remove substring from string

  NSString *str=@"1,2,3,4";
  int numberToRemove = 4;

 str = [str stringByReplacingOccurrencesOfString:[NSString stringWithFormat:@"%d",numberToRemove] withString:@""];
 str = [str stringByReplacingOccurrencesOfString:@",," withString:@","];

This will help.


NSString *str=@"1,2,3,4";
[str stringByReplacingOccurrencesOfString:@"3," withString:@""];

That will remove ALL occurrences of @"3," in str.

If you want to remove only the first occurrence of @"3,":

NSString* str = @"1,2,3,4";
NSRange replaceRange = [str rangeOfString:@"3,"];
if (replaceRange.location != NSNotFound){
    NSString* result = [str stringByReplacingCharactersInRange:replaceRange withString:@""];
}

Hope this helps.