Reputation: 1
i have a string containing tabs and newlines "\r\n\r\n\t\r\n\t\t\r\n\t\t\t\r\n\t\t\t\t\r\n\t\t\t\t\t\r\n\t\t\t\t\t\tTHIS IS THE STRING \r\n\t\t\t\t\t\r\n\t\t\t\t\t\t". I have to remove multiple blank lines if it has .If it has ony one blank line ,i have to omit it.
So i tried using
NSString *finalString = [orginal stringByReplacingOccurrencesOfString:@"^(.*)(\r\n\t){2,100}+"
withString:@""
options:NSRegularExpressionSearch
range:NSMakeRange(0,orginal.length)];
to remove newlines .Managed to remove few blank lines ,but its not working for all.Also i need to remove tab space.As i new to regex expression, any help will be appreciated.
Upvotes: 0
Views: 170
Reputation: 9835
Easier method would be the following:
finalString = [finalString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
Upvotes: 1