How to find a first letter in a string?

85 次查看(过去 30 天)
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?

采纳的回答

Jan
Jan 2017-3-29
编辑:Jan 2017-3-29
str = '2017-03-28_155051 - JoaquinLR_600fps_ForeheadChestWrist_5minRest';
idx = find(isletter(str), 1);
name = strtok(str(idx:end), '_');

更多回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by