Filter löschen
Filter löschen

split a string with strsplit unique

1 Ansicht (letzte 30 Tage)
Patrick Brown
Patrick Brown am 6 Apr. 2017
Kommentiert: Star Strider am 7 Apr. 2017
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?

Akzeptierte Antwort

Star Strider
Star Strider am 6 Apr. 2017
Experiment with the regexp function.
Example:
a='Position=a.Velocity=b.Acceleration=c.';
Vel = regexp(a, '(?<=Velocity=)\w', 'match')
Vel =
cell
'b'
  2 Kommentare
Patrick Brown
Patrick Brown am 7 Apr. 2017
and in the case that you have more than one letter for example
a='Position=ah.Velocity=bl.Acceleration=ck.';
Star Strider
Star Strider am 7 Apr. 2017
... 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'

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by