Replace each characters of strings with '-'
Ältere Kommentare anzeigen
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 Kommentare
KSSV
am 10 Aug. 2017
It is working fine right????_y_ is replaced by '_'....what you expect?
Suresh Dahal
am 10 Aug. 2017
Bearbeitet: Suresh Dahal
am 10 Aug. 2017
Akzeptierte Antwort
Weitere Antworten (1)
Walter Roberson
am 10 Aug. 2017
regexprep(B, c, '-')
or
B(B==c) = '_';
3 Kommentare
Suresh Dahal
am 10 Aug. 2017
Walter Roberson
am 10 Aug. 2017
Bearbeitet: Jan
am 10 Aug. 2017
B(:) = '-';
Jan
am 10 Aug. 2017
+1 for the last comment.
Kategorien
Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!