Find and replace in a character array

9 vues (au cours des 30 derniers jours)
vedesh Mohit
vedesh Mohit le 6 Mar 2020
Modifié(e) : BobH le 6 Mar 2020
Hey, I have this character array F='(B~C) + (~AB)'. How can I assess the array to locate all the terms that has a ~ before it and replace it with a ('). So ~C should be C'. Therefore I would like F to be F=(BC') + (A'B)

Réponse acceptée

Walter Roberson
Walter Roberson le 6 Mar 2020
F='(B~C) + (~AB)'
F = regexprep(F, '~(.)', '$1''')

Plus de réponses (1)

BobH
BobH le 6 Mar 2020
Modifié(e) : BobH le 6 Mar 2020
See regexprep and remember that to get a single-quote it must be doubled up in the replacement string
F='(B~C) + (~AB)';
regexprep(F,'~(.)','$1''') % ~ plus next character into that character plus single quote
ans =
(BC') + (A'B)

Catégories

En savoir plus sur Operators and Elementary Operations dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by