1. RE: text to number 2
- Posted by "C. K. Lester" <cklester at yahoo.com> Jan 28, 2002
- 455 views
> 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. First, {"-","1","2",".","2"} is not a string; it's a series (or array) of strings, the first being "-" and the last being "2". "-12.2" is a string. If you really need to get {"-","1","2",".","2"} as a value, you'll have to do this: for t=1 to length(myArray) do -- for each value in the array myTxt &= myArray[t] -- make it part of the new string end for myNum = sprintf("%d",{myTxt}) -- get the value of the new string using sprintf() I think that should work.
2. RE: text to number 2
- Posted by dmccu at connect.ab.ca Jan 30, 2002
- 426 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 > >
3. RE: text to number 2
- Posted by Kat <gertie at PELL.NET> Jan 30, 2002
- 473 views
On 31 Jan 2002, at 6:04, dmccu at connect.ab.ca wrote: > > Irv, > > What is strtok.s? "s" ? It's ".e". It's an include that treats "words" or words in a sentence, sequence, data line, etc as entities, separated by things like spaces, commas, semicolons, or whatever you specify. The strtok functions let you do things to words in sentences like you would characters in strings, like reptok(), deltok(), gettok(), etc etc.. So for line = {"Smith","Alice",1234,2002,"xyz45abc"} field1 = gettok(line,1,44) -- 44 is ascii for comma field1 = "Smith" count = numtok(line,44) -- count = 4 so you can pick out words or data fields or tags easily. http://www.rapideuphoria.com/strtok.zip Kat