Azzera filtri
Azzera filtri

is there a more efficient way to omit certain characters from a string without using loops?

1 visualizzazione (ultimi 30 giorni)
Hello. I have to take out characters from a string. I am using strrep. :
newsf = strrep(sf, 'C', '');
newsf = strrep(newsf, 'R', ''); n ewsf = strrep(newsf, 'E', '');
newsf = strrep(newsf, 'P', ''); newsf = strrep(newsf, 'SQ', '');
newsf = strrep(newsf, '1', '');
newsf = strrep(newsf, '2', '');
newsf = strrep(newsf, '3', '');
newsf = strrep(newsf, '4', '');
etc
I have tried using ~= for the characters I want but it won't accept that. Thanks for your time

Risposta accettata

Cedric
Cedric il 2 Mag 2013
Modificato: Cedric il 2 Mag 2013
One way would be
newsf = regexprep(sf, '([CREP1-4]|SQ)', '') ;
but what does "etc" encompass?

Più risposte (0)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by