필터 지우기
필터 지우기

How to replace a particular string in text file

조회 수: 186 (최근 30일)
arun
arun 2013년 10월 18일
댓글: Cedric 2013년 10월 19일
I have a problem related to efficiency, the code given below will replace the string and with '' an ' .' the code is working properly for small size text file ,but the main problem i am facing is that if there are approx 40,0000+ lines in text file then it is taking too much time that no one can't wait so please can anyone suggest me something different which run faster than this, Thanks in advance.
fid = fopen('input.txt','r');
f=fread(fid,'*char')';
fclose(fid);
f = regexprep(f,' ','');
f = regexprep(f,' ',' .');
fid = fopen('output.txt','w');
fprintf(fid,'%s',f);
fclose(fid);

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2013년 10월 18일
편집: Azzi Abdelmalek 2013년 10월 18일
strrep is faster then regexprep
f = strrep(f,' ','');
f = strrep(f,' ',' .');
  댓글 수: 17
arun
arun 2013년 10월 19일
yes, now i am using
f = regexp(f,'\S*_','split')
To get the following output,
VBD JJ IN VBN NN VB DT NN
VBD JJ IN VBN NN VB DT NN
These statement are much better.
Thanks for your efforts and for your valuable suggestions.
Cedric
Cedric 2013년 10월 19일
You're welcome!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by