how to remove strings
조회 수: 4 (최근 30일)
이전 댓글 표시
I tried to read a file named new.txt which contains information like
hello23,hi10
i tried to read it using textread and file name but i get it as
'hello23,hi10'..i need to be displayed as
hello23 hi10
please tell how to display by removing the strings ,else is there any command to read and display like above
댓글 수: 2
TAB
2012년 1월 3일
If your file contains data like this
hello23,hi10
hello24,hi11
hello25,hi12
....
You can combine read and replacement commands as
strrep(textread('MyFile.txt','%s'),',',' ')
It will return cell array having strings without ','
Walter Roberson
2012년 1월 3일
textread() is considered obsolete and will probably be removed from the language soon. textscan() is its replacement.
채택된 답변
TAB
2012년 1월 3일
As I understood, you want to remove the comma(,) from the string. You can do it by
str='hello23,hi10';
newstr=strrep(str,',',' ');
%OR
str=strrep(str,',',' ');
추가 답변 (1개)
Walter Roberson
2012년 1월 3일
fid = fopen('new.txt','rt');
datacell = textscan('%s%s', 'delimiter', ',', 'CollectOutput', 1);
fclose(fid);
char(strcat(datacell{1}(:,1), ' ', datacell{1}(:,2)))
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!