MATLAB 判断字符串中是否含有特定的字符

这个程序的目的是,逐行读取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);

 或者使用contains()函数:

filename='/media/dell/D/qcc/code/pointnet/pointnet2-master/data/dianyun_biaoxian_yifenlei/5-10_dashline_seg_python_dealwith.xyz';
>> contains(filename,'dashline')

ans =

  logical

   1
 

posted on 2020-11-17 19:50  一杯明月  阅读(9005)  评论(0编辑  收藏  举报