How to split a numrical-charcater String

I want to split the string "R88L1R607L10R1293" such that I should get "R", "88", "L", "1", "R", "607", "L", "10", "R", "1293".

Antworten (2)

Akira Agata
Akira Agata am 17 Jan. 2018

1 Stimme

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
Stephen23 am 17 Jan. 2018

0 Stimmen

>> 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

Kategorien

Gefragt:

am 17 Jan. 2018

Beantwortet:

am 17 Jan. 2018

Community Treasure Hunt

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

Start Hunting!

Translated by