Borrar filtros
Borrar filtros

split a string with strsplit unique

2 visualizaciones (últimos 30 días)
Patrick Brown
Patrick Brown el 6 de Abr. de 2017
Comentada: Star Strider el 7 de Abr. de 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?

Respuesta aceptada

Star Strider
Star Strider el 6 de Abr. de 2017
Experiment with the regexp function.
Example:
a='Position=a.Velocity=b.Acceleration=c.';
Vel = regexp(a, '(?<=Velocity=)\w', 'match')
Vel =
cell
'b'
  2 comentarios
Patrick Brown
Patrick Brown el 7 de Abr. de 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 el 7 de Abr. de 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'

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by