How to replace multiple strings with another string
조회 수: 8 (최근 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에서 Workspace Variables and MAT Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!