|
|
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.
|
|