How to replace multiple strings with another string
12 次查看(过去 30 天)
显示 更早的评论
Hello! I am trying to replace multiple words in a string with a single word. For example the sentence would be Hello girl and cat and I want to change it to Hello boy and boy. I've tried to format it as s being Hello girl and cat and then strrep (s, 'girl' 'cat', 'boy')
Thank you!
0 个评论
采纳的回答
Azzi Abdelmalek
2016-8-18
编辑:Azzi Abdelmalek
2016-8-18
str='Hello girl and cat'
out=regexprep(str,'girl|cat','boy')
%If you want to use strrep
str='Hello girl and cat'
out=strrep(str,'girl','boy')
out=strrep(out,'cat','boy')
2 个评论
HIRAKJYOTI BASUMATARY
2018-1-21
@Azzi Abdelmalek Sir : if i have a string aa='robotic robot'; and if i use bb=strrep(aa,'robot','robotic') then it gives me 'roboticic robot' ; instead i want the output to be 'robotic robotic' . So Sir, how can i be able to achieve it ?
Pearl
2019-1-25
I would use regexprep
aa='robotic robot';
out = regexprep(aa,'robot$','robotic');
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Robotics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!