Re: How to convert sequence of characters to numbers

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


Umm, s[1] is '2' , not 2, and '2' = 50, 2 = 2. Likewise s[1..4] = "2012".

I think you get the idea.

useless

Yes, and '0' is 48.

The expression "20121018123010" - '0' is equivalent to {50, 48, 49, 50, 49, 48, 49, 56, 49, 50, 51, 48, 49, 48} - 48 which equals {2, 0, 1, 2, 1, 0, 1, 8, 1, 2, 3, 0, 1, 0}

Now s[1..4] is {2, 0, 1, 2} which multiplied out gives you the year as an integer.

Edit: Corrected conversion error

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

Search



Quick Links

User menu

Not signed in.

Misc Menu