Tuesday, June 4, 2013

Powershell: testing string length validations

Every time I do this it makes me smile.

If you write apps that have input fields that have max lengths that are validated, then occasionally you may need to test your validations.  I used to do this by typing "this is a really really really long string that should break the validations" and the copying and pasting that over and over until I thought I'd gotten it long enough to exceed the max length.

Now I just switch over to powershell (which I always have conveniently open and ready) and I type:
"quite long" * 100 | clip.exe


"quite long" just happens to be exactly 10 characters long, so this generates a string which is 1000 characters long that looks like "quite longquite longquite long..."  Piping that string to clip.exe saves it on your clipboard. Now just paste into the field you want to test and you're all set!

No comments:

Post a Comment