Can you use replace to remove all characters that aren't letters from a string?
45 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Zach Adams
le 27 Oct 2019
Réponse apportée : Steven Lord
le 28 Oct 2019
I was wondering if I can use replace(str, ~['A':'Z' 'a':'z'], ' ') to replace all values that are not letters with an empty character. For example, if the string was 'I; love123 you-+'
I would need it to make a new string that is 'I love you'. Additionally, if this is not possible is there another way of doing this?
0 commentaires
Réponse acceptée
Steven Lord
le 28 Oct 2019
You can use isstrprop to create a mask for various categories of characters then use that mask to extract just all letters, or just all numbers, etc.
0 commentaires
Plus de réponses (1)
Shubham Gupta
le 27 Oct 2019
Modifié(e) : Shubham Gupta
le 27 Oct 2019
Try
str = 'I; love123 you-+';
str_new = regexprep(str,'[^a-zA-Z\s]','');
Voir également
Catégories
En savoir plus sur Characters and Strings 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!