Lasso Soft Inc. > Home


AuthorJason Huck
LicensePublic Domain
Posted04 Jan 2008
Updated04 Jan 2008
More by this author...


This tag accepts a string and a number of characters, and returns the string truncated to that length. It makes allowances for whitespace and punctuation, and appends an ellipsis character to the end. A complete description can be found here.

Sample Usage

var('str') = 'The quick, brown-fox jumps over the "lazy" dog.'; 
    loop_count + ' - ' + string_truncate($str, loop_count) + '\n'; 

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

	-req='length', -type='integer', -copy,
	-description='Truncates the given string to the given number of characters.'
	// if the original string is shorter than or equal to the desired length,
	// just return it unaltered.
	#text->size <= #length ? return(#text);
	local('out') = string;
	// while #out is empty, #length is still greater than zero,
	// and the last character of the new string is not whitespace...
	while(!#out->size || !#out->iswhitespace(#out->size) && #length);
		// store a new substring in #out
		#out = #text->substring(1, #length);
		// decrement #length by 1
		#length -= 1;
	// if we reached zero, return nothing
	!#length ? return;
	// remove any trailing non-alphanumeric characters and whitespace
	#out = string_replaceregexp(
	// return the final result with an ellipsis character appended
	return(#out + '…');	

Related Tags


No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home



©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft