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!