How to find a first letter in a string?

조회 수: 22 (최근 30일)
Mark Golberg
Mark Golberg 2017년 3월 29일
편집: Stephen23 2017년 3월 29일
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