[String_Truncate]

Description

Link: [String_Truncate]
Author: John Burwell
Category: String
Version: 8.x
License: Public Domain
Posted: Apr. 19, 2006
Updated: Apr. 19, 2006
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.

Parameters

-String string, required The input string to be truncated
-Length integer, required The maximum length of the output string
-Ellipsis string, optional A string to append if the input is actually truncated

Sample Usage

[String_Truncate: $long_string, -Length=20, -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
13
14
15
16
17
18
19
20
21
Define_Tag: 'String_Truncate',
  -Required='String',
  -Required='Length',
  -Optional='Ellipsis',
  -Description='Returns a string truncated to the specified -Length. An optional -Ellipsis parameter specifies a string to append if the string is actually truncated.';
  
  Local: 'input_string'   = (String: (Local: 'String'));
  Local: 'max_length'     = (Integer: (Local: 'Length'));

  Local: 'postfix_string' = (String: (Local: 'Ellipsis'));

  If: #input_string->(Size) <= #max_length;
    Return: #input_string;
  
  Else;
    Return: (String_Extract: #input_string, -StartPosition=1, -EndPosition=#max_length) + #postfix_string;
  
  /If;

/Define_Tag;

 

Related Tags



Comments

none

Email:


Password:



Newest

Most Popular

Support tagSwap.net