아래의 strBody에 search를 replace로 교체하는 방법..
NSMutableString *strBody = [NSMutableString stringWithString:_noticeInfo.body]; NSString *search = @" "; NSString *replace = @" ";
1. range를 바꿔가며 패턴을 찾고 교체
NSRange range = [strBody rangeOfString:search]; while(range.location != NSNotFound){ [strBody replaceCharactersInRange:range withString:replace]; range = [strBody rangeOfString:search]; }
2. range를 문자열 전체로 잡고 한번에 교체
NSRange range = NSMakeRange(0, [strBody length]); [strBody replaceOccurrencesOfString:search withString:replace options:NSLiteralSearch range:range];