Lasso Soft Inc. > Home

[string_truncate9]

Linkstring_truncate9
AuthorJonathan Guthrie
CategoryString
Version9.x
LicensePublic Domain
Posted05 Nov 2010
Updated05 Nov 2010
More by this author...

Description

String_Truncate takes three parameters: an input string, a -Length integer, and an optional -Ellipsis string. It returns a string no longer than the specified -Length, appending the optional ellipsis if the string is actually truncated. If the input string is shorter than the specified length, the full input string is returned and no ellipsis is appended. Note: The length of the ellipsis is not counted when truncating the input string. The string is truncated to the specified length before the ellipsis is added.

Note, this is a port of John Burwell's tag for 8.x
http://tagswap.net/String_Truncate/

Sample Usage

string_truncate(#mystring,10)
string_truncate(#mystring,-length=10,-ellipsis='...')

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.

define string_truncate(string::string,length::integer,ellipsis::string='...') => {
  // Returns a string truncated to the specified -Length. An optional -Ellipsis parameter specifies a string to append if the string is actually truncated.

	if(#string->Size <= #length) => {
	    return #string
	else 
		return string_extract(#string, -StartPosition=1, -EndPosition=#length) + #ellipsis
	}
}
define string_truncate(string::string,-length::integer,-ellipsis::string='...') => {
  return string_truncate(#string,#length,#ellipsis)
}

Comments

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