Replace character with another
60 ビュー (過去 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!