how to remove strings

4 次查看(过去 30 天)
kash
kash 2012-1-3
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
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
Walter Roberson 2012-1-3
textread() is considered obsolete and will probably be removed from the language soon. textscan() is its replacement.

请先登录,再进行评论。

采纳的回答

TAB
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 个评论
kash
kash 2012-1-3
Thanks Tabrex is there any input function to read as i said

请先登录,再进行评论。

更多回答(1 个)

Walter Roberson
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)))

类别

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