RE: text to number 2
- Posted by dmccu at connect.ab.ca Jan 30, 2002
- 425 views
Irv, What is strtok.s? I haven't heard of that before. Yes there are numbers mixed in with the text at random places and I have to extract the numbers from the text file I read in eg X3.5476Y5.0776 I have to take the numbers out and do math calculations on them in some cases, then return them. Irv Mullins wrote: > dmc wrote: > > ok, I have reviewed the value library function for converting a > > sequence to a number, but how do you get a sequence like > > {"-","1","2",".","2"} to be {"-12.2"} as the function needs it to be? > > Or am I missing something obvious? I need to make a file filter and I > > need to be able to convert back and forth regularly from string to > > numeric. > > The question no one has asked is: How are you getting > that strange sequence in the first place? > > You mention file filters, so I'm guessing you're reading > them from files. If so, you're just going about that in > the wrong way. > > If the files are pure numeric, then get() should work, no > conversion necessary. > > If the files are mixed text and numbers, then > you can either slice the numbers out, i.e. line[12..16] > if they are column-aligned, or if the numbers appear in > random places within a line, use gets() to read in the line, > and then parse the number(s) out with strtok.s, then convert > with value() > > A sample of the input data would help. > > Regards, > Irv > >