Borrar filtros
Borrar filtros

Steparate a sting using strtok function

2 visualizaciones (últimos 30 días)
Lily
Lily el 4 de Nov. de 2013
Respondida: Image Analyst el 4 de Nov. de 2013
Hi I'm trying to separate a string (a-b-c-d) into three parts or a-b c d. I would like to use strtok function ( http://www.mathworks.se/help/matlab/ref/strtok.html ) to solve this problem.
example = 'a-b-c-d';
[token, remain] = strtok(example,remain); %This doesn't work :(
I would like my end result to be like this:
'a-b' 'c' 'd'
Thx for your help :)

Respuestas (2)

Sean de Wolski
Sean de Wolski el 4 de Nov. de 2013
If you're on R2013a or newer (I believe), use strsplit:
example = 'a-b-c-d';
pieces = strsplit(example,'-')
And for more info
doc strsplit
If you're on an older release, either upgrade :) or use regexp with the 'split' option:
pieces = regexp(example,'-','split')
  1 comentario
Lily
Lily el 4 de Nov. de 2013
Editada: Lily el 4 de Nov. de 2013
thx, but do you know how to do this with strtok function? I really want to know how to implement it :)

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 4 de Nov. de 2013

Categorías

Más información sobre String Parsing en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by