string text manipulation - adding data based on previous data in the string
Ältere Kommentare anzeigen
Hi,
I have a string (char array) looking as follows:
Time,<Message_CMD>element1,<other_meesage>elemenX,<Message_CMD>element2,<Message_RPT>element3,
I'd like to change the string so that the element will contain the type of the message
Time,<Message_CMD>element1CMD,<other_meesage>elemenX,<Message_CMD>element2CMD,<Message_RPT>element1RPT,
What is the simplest way to do it?
EDIT: note that element1 is both CMD and RPT
Akzeptierte Antwort
Weitere Antworten (2)
Walter Roberson
am 2 Jun. 2022
Bearbeitet: Walter Roberson
am 2 Jun. 2022
regexprep(S, {'element[12]', 'element3'}, {'$1CMD', '$1RPT'})
2 Kommentare
michael
am 2 Jun. 2022
Walter Roberson
am 2 Jun. 2022
regexprep(S, {'element[12]', 'element3'}, {'$1CMD', 'element1RPT'})
David Hill
am 2 Jun. 2022
m=replace(m,'element1','element1CMD');
m=replace(m,'element2','element2CMD');
m=replace(m,'element3','element3RPT');
1 Kommentar
michael
am 2 Jun. 2022
Kategorien
Mehr zu Characters and Strings finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!