Separating last two digits from number
Hi
I was wondering if anyone could help with a problem I’ve come up against regarding separating the last two digits from the end of a longer number?
I imagine a regexp may do the trick, but in my experience, which is unfortunately rather limited, I can’t seem to get the regexp to deal with the fact that i'm trying to separate the last two digits from numbers which are of differing length. Just for context, the final two digits on each number represent an index value which I have nested within the longer number prior to a sorting process. This will hopefully (!) allow me to recall some timing data associated with the index value.
So, for example I have a list of numbers such as:
1933
3134
13935
14036
60237
110838
You can see that the final two digits are index numbers referencing the numbers preceding them. After processing I need the list to look like this:
19 33
31 34
139 35
140 36
602 37
1108 38
If each number had the same amount of digits (lets say four) I could use regexp (\\d\\d) to separate the preceding numbers from the index, but as the length of each number is not set to a fixed length this solution doesn’t work.
Any ideas how I might be able to get my totally Heath Robinson and probably completely inefficient patch to work?
Thanks for your help
J
[/ 100] and [% 100]
`
Or with regexp.
Well that was simple!
Thanks so much
J
I have a list of numbers such as...
Good old modulo is about 7 times faster than cryptic [regexp] (which is at a distinct disadvantage against a math operator in this case). If your input is a list, you can use [vexpr $i1 % 100], which is even faster than than calculating a series of iterated values through [% 100]. Another novel option is [atoi]-->[zl ecils 2] -->[itoa], with similar drawbacks as [regexp] - but really, they are all plenty fast for this sort of thing.
My input is a list so have gone with [vexpr $i1 % 100] .
Thanks to everyone for their help!