Truncate String

Truncate a string to a specified length with ellipsis.

Code

General
str.length > length ? str[0, length - 3] + '...' : str

Parameters

The string to truncate

Maximum length including ellipsis

Server

More Ruby Snippets