truncate
Modified on Wed, 02 Aug 2023
Description
Truncate string if it's longer than the given maximum string length. The last characters of the truncated string are replaced with the omission string which defaults to '...'
Syntax
truncate(text, options)
Parameters
Input Parameter | Type | Description |
---|---|---|
text | string | The string to truncate. |
options (optional) | object | The options object. It can be used to configure length (the maximum string length), omission (the string to indicate text is omitted) and the separator (the separator pattern to truncate to) settings. EX: {'length' : 30, 'omission' = '...', separator = '--'} |
Return value
Type |
---|
string |
Sample
Example | Result | Description |
---|---|---|
truncate('abcd1234abcd1234abcd1234abcd1234') | 'abcd1234abcd1234abcd1234abc...' | Truncate string with default settings : maximum length 30, omission string '...' |
truncate('abcd1234abcd1234', {'length' : 10, 'omission' : '**'}) | 'abcd1234**' | Truncate string to maxiumum length 10 with omission string as '**' |
truncate('abcd1234abcd1234', {'length' : 10, 'omission' : '**', 'separator' : '1'}) | 'abcd**' | Truncate string to maxiumum length 10 with omission string as '**' and with seperator '1' |
To view all the String functions, click here.
Was this article helpful?
That’s Great!
Thank you for your feedback
Sorry! We couldn't be helpful
Thank you for your feedback
Feedback sent
We appreciate your effort and will try to fix the article