Replace letter with dot
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Does anybody know how to replace first letter as well as same subsequent letters of a word with dot in a string?
For instance:
'MOMENT AND INITIALIZATION'
i need: '.O.ENT AND .N.T.AL.ZAT.ON'
To note, I need all white spaces to be saved as they are.
0 commentaires
Réponses (1)
Star Strider
le 4 Mai 2020
Try this:
str = 'MOMENT AND INITIALIZATION';
newstr = str;
old = {'M','I'}';
for k = 1:numel(old)
newstr = strrep(newstr, old(k),{'.'});
end
newstr
producing:
newstr =
1×1 cell array
{'.O.ENT AND .N.T.AL.ZAT.ON'}
Voir également
Catégories
En savoir plus sur Characters and Strings dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!