Wednesday, September 03, 2008

Prototype: How to truncate a string

A very nice utility to truncate a string in prototype:

var test_string = "this is a test string/0";
var new_string = test_string.truncate(test_string.length- 2, '');

So the new_string should be "this is a test string. Remember though, don't ignore the second paremeter, which now specify there will not be any suffix.