Replace character with another
58 次查看(过去 30 天)
显示 更早的评论
Hello.
Which command should I use in order to replace one character with another?
(For example in the word: Big, I would like to replace character i with a.)
0 个评论
采纳的回答
Walter Roberson
2020-12-6
S = 'Big'
S(S == 'i') = 'a'
T = 'Big'
T = strrep(T, 'i', 'a')
U = 'Big'
U = regexprep(U, 'i', 'a')
6 个评论
Ameer Hamza
2020-12-7
Note that, regexprep() might create "unexpected" result, for example,
>> out = regexprep(str,{'i','a'},{'a','e'})
out =
'Oel'
Depending on what you want, this might be the required outcome. But in such situation, I prefer replace()
>> out = replace(str,{'i','a'},{'a','e'})
out =
'Oal'
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Migrate GUIDE Apps 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!