Replacing String Values By Position
조회 수: 16 (최근 30일)
이전 댓글 표시
I wanted to know how I could assign new values to a string based on their position. For example, if I have the following string 'test rest' and I do a strfind('test rest', 'e') and am given the output 2 7. How can I use that to replace the 'e' with another arbitrary value such as 'r', so that my output reads 'trst rrst.' I'd like to do this with out using something like strrep()
Thank you.
댓글 수: 0
채택된 답변
Matt Fig
2012년 9월 15일
You don't need to use linear indexing (STRFIND) here at all. Just use logical indexing.
str = 'test rest';
str(str=='e')='r'
댓글 수: 0
추가 답변 (1개)
참고 항목
카테고리
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!