필터 지우기
필터 지우기

split a string with strsplit unique

조회 수: 2 (최근 30일)
Patrick Brown
Patrick Brown 2017년 4월 6일
댓글: Star Strider 2017년 4월 7일
I have this string
a='Position=a.Velocity=b.Acceleration=c.'
strsplit(a,{'Velocity=','.'})
ans =
'Position=a' 'b' 'Acceleration=c' ''
but the result I want in ans is only b how I can do it?

채택된 답변

Star Strider
Star Strider 2017년 4월 6일
Experiment with the regexp function.
Example:
a='Position=a.Velocity=b.Acceleration=c.';
Vel = regexp(a, '(?<=Velocity=)\w', 'match')
Vel =
cell
'b'
  댓글 수: 2
Patrick Brown
Patrick Brown 2017년 4월 7일
and in the case that you have more than one letter for example
a='Position=ah.Velocity=bl.Acceleration=ck.';
Star Strider
Star Strider 2017년 4월 7일
... add a ‘+’ after the ‘\w’ to match more than one letter:
a ='Position=ah.Velocity=bl.Acceleration=ck.';
Vel = regexp(a, '(?<=Velocity=)\w+', 'match')
Vel =
cell
'bl'

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

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