获得一个特定的段落. txt文件
1视图(30天)
显示旧的评论
接受的答案
沃尔特·罗伯森
2016年7月15日
filecontent = fileread (“YourFile.txt”);
testnum = 2;
par_begin_pos = regexp (filecontent sprintf (“^测试% d 'testnum),“lineanchors”);
如果isempty (par_begin_pos)
流(“不段# % d文件”,testnum);
返回
结束
par_end_pos = regexp (filecontent sprintf (“^测试% d 'testnum + 1),“lineanchors”);
如果isempty (par_end_pos)
par_end_pos =长度(filecontent) + 1;%对测试文件的最后一件事
结束
paragraph_content = filecontent (par_begin_pos: par_end_pos - 1);