Replace character with another
58 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ivan Mich
el 6 de Dic. de 2020
Comentada: Ameer Hamza
el 7 de Dic. de 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 comentarios
Respuesta aceptada
Walter Roberson
el 6 de Dic. de 2020
S = 'Big'
S(S == 'i') = 'a'
T = 'Big'
T = strrep(T, 'i', 'a')
U = 'Big'
U = regexprep(U, 'i', 'a')
6 comentarios
Ameer Hamza
el 7 de Dic. de 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'
Más respuestas (0)
Ver también
Categorías
Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!