필터 지우기
필터 지우기

Replace repeated pattern in text

조회 수: 1 (최근 30일)
GEORGIOS BEKAS
GEORGIOS BEKAS 2018년 1월 10일
답변: Guillaume 2018년 1월 11일
I wrote the following code for a file that I attach, but it is not working.
filecontent = fileread('C:\Users\User\Desktop\Document 8.txt')
filecontent6 = regexprep( filecontent ,' 6; !- Minimum Number of Warmup Days' , ' 5; !- Minimum Number of Warmup Days' )
fid = fopen('C:\Users\User\Desktop\Document 5.idf', 'wt')
assert(fid > 0, 'failed to open file for writing');
fwrite(fid, filecontent6)
fclose(fid)

채택된 답변

Guillaume
Guillaume 2018년 1월 11일
"but it is not working"
That is a very useless statement if you don't tell us in what way it is not working, or what you expected the code to do.
It is not working because:
  1. You've got an extra space in the name of the file in your fileread call, 'Document 8' vs 'Document8' ?
  2. the string ' 6; !- Minimum Number of Warmup Days' is not present in your document? Note that the same string with one less space before the 6 is present.
  3. Some other reason?
I suspect that your problem is point 2.
Note that if you don't know how to build regular expressions, I would recommend that you use strrep instead of regexprep.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by