Replace character with another
58 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Ivan Mich
il 6 Dic 2020
Commentato: Ameer Hamza
il 7 Dic 2020
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 Commenti
Risposta accettata
Walter Roberson
il 6 Dic 2020
S = 'Big'
S(S == 'i') = 'a'
T = 'Big'
T = strrep(T, 'i', 'a')
U = 'Big'
U = regexprep(U, 'i', 'a')
6 Commenti
Ameer Hamza
il 7 Dic 2020
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'
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Migrate GUIDE Apps in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!