Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
tokenizing string

Subject: tokenizing string

From: Pr B

Date: 10 Aug, 2011 14:23:10

Message: 1 of 2

i have an issue with strtok. I am trying to parse a string of the following form:

a = '10_ash_ajs_74_29_ah_23_ah_59'

i am only interested in the number right after the last underscore in the string, reading left to right. this would be the number 59. i am trying to use [tok,remain] = strtok(a,'_') but remain always gives me '_ash_ajs_74_29_ah_23_ah_59'. i need to use successive calls to strtok to get to the part of the string i'm interested in by [tok,remain] = strtok(remain,'_'), but is there a better way to do this?

Subject: tokenizing string

From: Donn Shull

Date: 10 Aug, 2011 14:37:28

Message: 2 of 2

"Pr B" <pb2297@columbia.edu> wrote in message <j1u48e$jhh$1@newscl01ah.mathworks.com>...
> i have an issue with strtok. I am trying to parse a string of the following form:
>
> a = '10_ash_ajs_74_29_ah_23_ah_59'
>
> i am only interested in the number right after the last underscore in the string, reading left to right. this would be the number 59. i am trying to use [tok,remain] = strtok(a,'_') but remain always gives me '_ash_ajs_74_29_ah_23_ah_59'. i need to use successive calls to strtok to get to the part of the string i'm interested in by [tok,remain] = strtok(remain,'_'), but is there a better way to do this?

tok = fliplr(strtok(fliplr(a),'_'))

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us