Re: text to number 2
- Posted by Irv Mullins <irvm at ellijay.com> Jan 31, 2002
- 478 views
On Thursday 31 January 2002 01:04 am, you wrote: > > Irv, > > What is strtok.s? Strtok.e is an "include" file written by Gabriel Boehm and Kat, which (among many other things) breaks strings down into units based on a separator token, such as spaces or ':' or whatever. > 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. Below is a routine that will extract numbers per your example. This is not a general purpose routine. This illustrates *one* way, but more info on the actual format of the data would be needed before we could come up with a workable scheme. Do the numbers all run together like your example? Are there always fixed markers such as X and Y? Can the input contain other words that might throw off the parsing by having X or Y in them? Also, be aware that you probably won't be able to "return" values to a text file - you'll have to write the output to a new file. include get.e atom fn object Xval, Yval integer xp, yp object line fn = open("test.data","r") line = gets(fn) xp = match("X",line) yp = match("Y",line) Xval = value(line[xp+1..yp-1]) Yval = value(line[yp+1..length(line)]) if Xval[1] != GET_SUCCESS then puts(1,"Error evaluating X") else Xval = Xval[2] ? Xval end if if Yval[1] != GET_SUCCESS then puts(1,"Error evaluating Y") else Yval = Yval[2] ? Yval end if Regards, Irv