필터 지우기
필터 지우기

Steparate a sting using strtok function

조회 수: 2 (최근 30일)
Lily
Lily 2013년 11월 4일
답변: Image Analyst 2013년 11월 4일
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 :)

답변 (2개)

Sean de Wolski
Sean de Wolski 2013년 11월 4일
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
Lily
Lily 2013년 11월 4일
편집: Lily 2013년 11월 4일
thx, but do you know how to do this with strtok function? I really want to know how to implement it :)

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


Image Analyst
Image Analyst 2013년 11월 4일

카테고리

Help CenterFile Exchange에서 String Parsing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by