Friday, 23 May 2014

Remove white space & newline from both ends of a string and replace space by %20



This will remove white space and newline from both ends of a string:

NSString *newString = [oldString stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceCharacterSet]];

NSString *newString = [oldString stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];



This will remove white space and newline from any where in string:

//give %20 on space
NSString *string = [[NSString alloc]initWithFormat:@"%@",[yourString stringByReplacingOccurrencesOfString:@" " withString:@"%20" options:NSRegularExpressionSearch range:NSMakeRange(0, yourString.length)]];

No comments:

Post a Comment