Replace each characters of strings with '-'
显示 更早的评论
Hi, I want to replace all the characters of a string by '-', say, flowers will be like '-------'. Please tell me how am I supposed to do that. I am totally new to matlab. As a beginner I've done this so far.
%Select a word
B='skyyiy'
%input letter
c='y'
%stringlength
l=strlength(B)
%indices of letters occurring
d=strfind(B,c)
newStr=strrep(B,c,'-')
2 个评论
KSSV
2017-8-10
It is working fine right????_y_ is replaced by '_'....what you expect?
Suresh Dahal
2017-8-10
编辑:Suresh Dahal
2017-8-10
采纳的回答
更多回答(1 个)
Walter Roberson
2017-8-10
regexprep(B, c, '-')
or
B(B==c) = '_';
3 个评论
Suresh Dahal
2017-8-10
Walter Roberson
2017-8-10
编辑:Jan
2017-8-10
B(:) = '-';
Jan
2017-8-10
+1 for the last comment.
类别
在 帮助中心 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!