How to find a first letter in a string?

32 vues (au cours des 30 derniers jours)
Mark Golberg
Mark Golberg le 29 Mar 2017
Modifié(e) : Stephen23 le 29 Mar 2017
Hello,
I have the following string:
str = '2017-03-28_155051 - JoaquinLR_600fps_ForeheadChestWrist_5minRest';
I would like automatically extract from that string the name, which is JoaquinLR
what would be the best way to do it?
I was thinking maybe I'll find the first letter after space?
  1 commentaire
KSSV
KSSV le 29 Mar 2017
Read about regexp.

Connectez-vous pour commenter.

Réponse acceptée

Jan
Jan le 29 Mar 2017
Modifié(e) : Jan le 29 Mar 2017
str = '2017-03-28_155051 - JoaquinLR_600fps_ForeheadChestWrist_5minRest';
idx = find(isletter(str), 1);
name = strtok(str(idx:end), '_');

Plus de réponses (1)

Stephen23
Stephen23 le 29 Mar 2017
Modifié(e) : Stephen23 le 29 Mar 2017
This is easy with regexp or regexpi:
>> str = '2017-03-28_155051 - JoaquinLR_600fps_ForeheadChestWrist_5minRest';
>> regexpi(str,'[a-z]+','match','once')
ans = JoaquinLR

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!

Translated by