How to split a numrical-charcater String
Afficher commentaires plus anciens
I want to split the string "R88L1R607L10R1293" such that I should get "R", "88", "L", "1", "R", "607", "L", "10", "R", "1293".
Réponses (2)
Akira Agata
le 17 Jan 2018
You can separate it by using regexp function, like:
strAll = "R88L1R607L10R1293";
strNum = regexp(strAll,'\d+','match'); % Extract numbers
strChar = regexp(strAll,'[A-Z]+','match'); % Extract alphabets
Stephen23
le 17 Jan 2018
>> S = 'R88L1R607L10R1293';
>> C = regexp(S,'([RL])(\d+)','tokens');
>> C = [C{:}];
>> C{:}
ans = R
ans = 88
ans = L
ans = 1
ans = R
ans = 607
ans = L
ans = 10
ans = R
ans = 1293
Catégories
En savoir plus sur Data Type Conversion dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!