Replace letter with dot
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Star Strider
2020-5-4
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'}
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!