Monday, July 25, 2011

PowerShell strings, ints and comparisons

I hit this doing a little bit of playing around over the weekend, porting some old BASIC progams into PowerShell.

Most of the time treating strings of digits as numbers "just works":

but at times it all goes horribly wrong

with the ASCII value of '5' being 53, we see that these comparisons are being done lexically.

What is needed in these circumstances is an explicit coercion some place down the line; like:

No comments :