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!