Re: How to convert sequence of characters to numbers

new topic     » goto parent     » topic index » view thread      » older message » newer message
casey said...

I need to convert a date/time string (sequence) of the format "20121018123010" into a sequence of numeric values of the format {2012,10,18,12,30,10} I'm looking for the fastest routine execution time possible. It looks like I could use breakup() and then maybe to_integer() or value() on each of the six elements. Am I missing something or is there a better way. Ultimately I need to poke2 each of the word values into a c_func call

Thanks, casey

Hi Casey,

I imagine that the fastest way would be to poke the string into memory and call a custom machine code routine that did the conversion AND called your C function.

However, if you wanted to use Euphoria then a custom routine would be fastest. You would not have to call breakup() or any other Eu functions as you could address and convert each element directly:

 
sequence s = "20121018123010" 
s -= '0' 
integer year = s[1]*1000 + s[2]*100 + s[3]*10 + s[4] -- year is now 2012 

I think you get the idea.

Spock

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu