Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: one-liner to parse an alpha-numeric string
Replies: 5   Last Post: Nov 22, 2005 12:41 PM

 Messages: [ Previous | Next ]
 Duane Bozarth Posts: 298 Registered: 1/25/05
Re: one-liner to parse an alpha-numeric string
Posted: Nov 21, 2005 2:40 PM

Jeff Kiecker wrote:
>
> Hey folks, got a question. I've spent several hours trying to figure
> this out (i.e., trying to understand format strings and such) with no
> success. Let me know if this can be done.
>
> I'd like to strip out several numbers from a string to use in future
> calculations. The caveat is I'd like to do this with a single line
> of code for each number (no if/then's, etc.)
>
> the string is basically denotes a tire size: 'P225/70R17',
> 'LT265/50R18', 'P245/45ZR18', etc.
>
> I would like to strip out each number and str2num it. The above
> three examples cover all the string possibilities prettymuch in that
> there is always one or two letters to start, and the 'R' sometimes
> has a letter before it.
>
> BUT, the first number is always 3 digits, and the last two numbers
> are always 2 digits.
>
> I'm looking for a solution like this
> SectionWidth = ... = 225
> AspectRatio = ... = 70
> RimDiameters = ... = 17
>
> I think i can do this with sscanf, but i can't figure it out, can
> anyone help?

Writing a function comes to mind...I didn't really play w/ it, but I
think I'd convert the characters to something like commas, eliminate
duplicates and then parse that. Something such as that seems the most
robust solution to me.

Date Subject Author
11/21/05 Jeff Kiecker
11/21/05 Duane Bozarth
11/21/05 Duane Bozarth
11/22/05 Philip Freeman
11/22/05 Jeff Kiecker
11/22/05 Duane Bozarth