這個程序的目的是,逐行讀取file.txt文件中的字符串,並判斷字符串中是否含有特定的字符,如果含有,再對字符串進行處理,然後寫入到新的TXT文檔中new_file.txt
fid=fopen('D:\new_file.txt','wt');
phns = 'D:\file.txt';
fpn = fopen (phns(1,:), 'rt'); %
while feof(fpn) ~= 1%
file = fgetl(fpn);
if ~isempty(strfind(file,'m'))
%如果字符串中含有“m”則執行if內的程序
end
fprintf(fid,'%s',file);
end
fclose(fid);
fclose(fpn);