1. RE: text to number 2

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

new topic     » topic index » view message » categorize

2. RE: text to number 2

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

new topic     » goto parent     » topic index » view message » categorize

3. RE: text to number 2

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

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu