How to split a numrical-charcater String
Show older comments
I want to split the string "R88L1R607L10R1293" such that I should get "R", "88", "L", "1", "R", "607", "L", "10", "R", "1293".
Answers (2)
Akira Agata
on 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
on 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
Categories
Find more on Data Type Conversion in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!