面试题:oc正则匹配 删除注释
来源:互联网 发布:淘宝花呗怎么开通不了 编辑:程序博客网 时间:2024/04/30 00:21
//// 现有文件: '/Users/gb/Documents/oc_test/test.m',// 请编写程序,将'/Users/gb/Documents/oc_test/test.m' 文件中所有的取出去除,将结果写入'test.i'中(或者用 NSLog 函数在控制台输出)#import <AppKit/AppKit.h>#import <Foundation/Foundation.h>int main(int argc, const char * argv[]) { @autoreleasepool { NSLog(@"hello!"); NSString *content=[NSString stringWithContentsOfFile:@"/Users/gb/Documents/oc_test/test.m" encoding:NSUTF8StringEncoding error:nil]; NSLog(@"content:%@",content); NSString * regexStr = @"/\\*.*\\*/|//.*"; NSError *error = NULL; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexStr options:NSRegularExpressionCaseInsensitive error:&error]; NSArray *result=[regex matchesInString:content options:0 range:NSMakeRange(0, [content length])]; if (result) { for (NSTextCheckingResult* item in result) {// str1 是每个和表达式匹配好的字符 NSString *str1 = [content substringWithRange:item.range]; NSLog(@" str 1 is %@",str1); } }else{ NSLog(@" 没有匹配到"); } } return 0;}
test.m文件
#import <Foundation/Foundation.h>// ;kjjk /*wertt /* ff */ */ fasdfint main(int argc, const char * argv[]){ /*ggggg /* ddddd */ // asdfee int a; // define a; NSLog(@"hello,world! /* "); // NSLog ; /* return */ return 0;}
0 0
- 面试题:oc正则匹配 删除注释
- 面试题:正则表达式匹配
- phpstorm正则匹配删除注释行
- 面试题53:正则表达式匹配
- 面试题57:正则表达式匹配*
- 面试题53:正则表达式匹配
- 剑指offer面试题:正则表达式匹配
- 面试题53:正则表达式匹配
- 面试题53. 正则表达式匹配
- OC中的正则匹配
- 百度面试题(简单的正则匹配)
- LeetCode 面试题 Regular expression matching(正则匹配)
- 《剑指Offer》学习笔记--面试题53:正则表达式匹配
- 【剑指Offer学习】【面试题53:正则表达式匹配】
- 面试题_53——正则表达式匹配
- 剑指offer-面试题53:正则表达式匹配
- 剑指offer--面试题53:正则表达式匹配
- 剑指Offer面试题53:正则表达式匹配 Java实现
- JAVA设计模式:抽象工厂模式
- 500A - New Year Transportation
- hadoop初级班(三)
- Java 用FileReader 和 FileWriter 进行文件读写(txt) (
- erlang 通过尾递归实现双层循环,并抽象出两向量的叉积的一般运算式
- 面试题:oc正则匹配 删除注释
- centos7_64安装jdk1.7
- JAVA设计模式:建造者模式
- Ubuntu14.04安装IPython、sublime text2并把sublime设为系统和IPython的默认编辑器
- IE文档模式
- my work note from new job
- Java中sql语句之通配符*
- MATLAB调用C/C++函数的方法
- 开发中注意点