Generating truncation-detection strings · Thu Apr 28, 06:30 PM

So, there I was, needing a way to test at which place a string would get truncated in a particular UI piece. I recalled vaguely the existence of a perl script that would generate a string that would work well for this sort of thing, but a couple minutes of googling led me nowhere useful. So I whipped up the solution in Ruby, which turned out to be faster than googling, even:

(0..499).each { |i| print "%03d." % i }

You get a string that looks like:

000.001.002.003...497.498.499.

To find the character position of a truncation, find the last period (’.’), multiply (the number before it + 1) times 4, and add any characters beyond the period. So, for example, if your truncated string ends in ”.352.353.3”, you multiply (353+1) * 4 and add 1, giving you 1417.

Of course, generalizing this to take a length parameter would be nice, but…if you need it, knock yourself out. As for me, I am working on my YAGNI skills .

-- David --

...