【发布时间】:2011-09-23 12:20:32
【问题描述】:
这是我的代码:
NSRegularExpression * regex;
- (void)viewDidLoad {
NSError *error = NULL;
regex = [NSRegularExpression regularExpressionWithPattern:@"<*>" options:NSRegularExpressionCaseInsensitive error:&error];
}
- (IBAction)findWord {
NSString * fileContents=[NSString stringWithContentsOfFile:[NSString stringWithFormat:@"%@/report1_index1_page1.html", [[NSBundle mainBundle] resourcePath]]];
NSLog(@"%@",fileContents);
NSString * modifiedString = [regex stringByReplacingMatchesInString:fileContents
options:0
range:NSMakeRange(0, [fileContents length])
withTemplate:@"$1"];
NSLog(@"%@",modifiedString);
}
我的 'modifiedString' 正在返回 (null)。为什么?我想用空格替换 '' 之间的任何字符,包括 ''。
【问题讨论】:
标签: iphone objective-c regex ios4 nsregularexpression