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 --
...
Archive by Date
- Administrative (51)
- Art (3)
- Books (14)
- Business (1)
- Clocks (8)
- Dating (1)
- Events (7)
- Flickr (1)
- Fonts (8)
- Human-Nature (1)
- Humor (5)
- Military (4)
- Misc (121)
- Movies (5)
- Music (68)
- OLE-DB (1)
- Poetry (4)
- Quotes (5)
- Relationships (1)
- Security (1)
- Shoes (2)
- Software (115)
- Spirits (11)
- Surveys (1)
- Tequila (6)
- Virtualization (9)
- Web (9)
- Website (20)
- Wood-Related (2)
- Writing (7)

