Turning an integer into an array of its digits

Get help using and writing Nisus Writer Pro macros.
User avatar
phspaelti
Posts: 1022
Joined: 2007-02-07 00:58:12
Location: Japan

Re: Turning an integer into an array of its digits

Post by phspaelti » 2019-10-02 05:57:20

Code: Select all

$my1997keys = Array.new()
foreach $key, value in $myhash
    if $value.find('1997')
        $my1997keys.push $key
    end
end
Pulling these keys into an Array may be useful, if you want to process them further, perhaps repeatedly. But since you will most likely need to loop through them again to do anything, you could really just do the comparison on the fly.

Also I am using .find to do the comparison. Nisus actually has a .containsString command which could be used instead. Not sure if there is any real advantage to one method or the other.

[PS: Sorry. Earlier I just wrote "foreach $key in $hash". But of course with hashes you have to do "foreach $key, $value in $hash".]
philip

Post Reply