【发布时间】:2014-03-25 13:29:43
【问题描述】:
我有一个文本文件,其内容例如:
[1] John where are you bring me copy number = 1 4 5
[2] Hi, Sam what is the cost of your calculator = 200 500 800
[3] Nancy, bring me the no. of copy that I gave you = 4 8 5
[4] Hi, how many litres of milk you have = 10 12 6
[5] Peter, give your copy numb = 23 45 32
& so on.
我对那些包含“复制”一词的行感兴趣。下面的代码为我提供了文本文件中包含“复制”一词的行号。
fid = fopen(‘my_file.txt', 'r');
C = textscan(fid, '%s', 'Delimiter', '\n');
fclose(fid);
% Search for string ‘copy’ and find all rows that matches it
D = strfind(C{1}, 'copy');
rows = find(~cellfun('isempty', D));
我想在另一个文本文件中打印带有“复制”一词的那些行。
【问题讨论】: