필터 지우기
필터 지우기

Why strrep() is unable to replace the string of following code.

조회 수: 2 (최근 30일)
sachin k p
sachin k p 2018년 9월 4일
답변: Walter Roberson 2018년 9월 4일
I have copied the entire content of the file to X.
ff='Downloads\python.txt';
fid=fopen(ff,'rt');
X = fread(fid) ;
fclose(fid) ;
X = string(X.') ;
Y = strrep(X,'name','verify') ;
fid = fopen(ff,'r+') ;
fprintf(fid,'%s',Y);
fclose (fid) ;
  댓글 수: 1
Geoff Hayes
Geoff Hayes 2018년 9월 4일
sachin - have you confirmed that name appears in your X? Is python.txt a text file or a binary file? (maybe this doesn't matter).

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

답변 (1개)

Walter Roberson
Walter Roberson 2018년 9월 4일
fread() defaults to using 'uint8=>double' so the results would all be in the range 0 to 255 . string() of that is going to result in a string array in which each entry is "0" to "255", and each byte was a separate string entry -- so each one is going to be 1, 2, or 3 characters long. None of those are going to match the four character long string 'name' as none of them are going to be anything other than characters that represent digits.
Consider using fileread() instead of fopen/fread/fclose .

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by