[string_truncate9]

Description

Link: [string_truncate9]
Author: Jonathan Guthrie
Category: String
Version: 9.x
License: Public Domain
Posted: Nov. 05, 2010
Updated: Jan. 01, 0001
More by this author...

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/

Parameters

none


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.
1
2
3
4
5
6
7
8
9
10
11
12
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

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net