替换:
[mutablestring replaceOccurrencesOfString:@"<" withString:@"<" options:0 range:NSMakeRange(0,[mutablestring length])];
[mutablestring replaceOccurrencesOfString:@">" withString:@">" options:0 range:NSMakeRange(0,[mutablestring length])];
正则表达式替换:
NSRegularExpression *regular;
regular = [[NSRegularExpression alloc] initWithPattern:@"</p>"
options:NSRegularExpressionCaseInsensitive
error:nil];
nomutablestring = [regular stringByReplacingMatchesInString:nomutablestring options:0 range:NSMakeRange(0, [nomutablestring length]) withTemplate:@"&&&"];
[regular release];
regular = [[NSRegularExpression alloc] initWithPattern:@"<p[^>]*TEXT-ALIGN: center[^>]*>"
options:NSRegularExpressionCaseInsensitive
error:nil];
nomutablestring = [regular stringByReplacingMatchesInString:nomutablestring options:0 range:NSMakeRange(0, [nomutablestring length]) withTemplate:@"<p>@center@"];
[regular release];
// 替换所有<>标签
regular = [[NSRegularExpression alloc] initWithPattern:@"<([^>]*)>"
options:NSRegularExpressionCaseInsensitive
error:nil];
nomutablestring = [regular stringByReplacingMatchesInString:nomutablestring options:0 range:NSMakeRange(0, [nomutablestring length]) withTemplate:@""];
[regular release];
去除字符串中所有得空格及控制字符:
responseString = [responseString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet ]];