ShortenStrings: Shortens strings by replacing the middle with a separator.

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Strings are shortened by replacing characters from the middle of the string with a separator.

Usage

1
ShortenStrings(strings, max.len=40, end.len=floor(max.len/2), sep='...')

Arguments

strings

A string of characters, or an array of strings.

max.len

The maximum length of the string. Must be at least 1+str_length(sep).

end.len

The length of the string retained after the separator.

sep

A separator that will be used to replace the middle of the string.

Details

If the input string is longer than max.len, then the string is shortened as follows. First, leading and trailing whitespace is removed. If the string is still longer than max.len then a start length is computed as:

start.len = max.len - end.len - str_length(sep)

Characters after start.len and before end.len are replaced with sep. If end.len is too large (as in the third example below) then it is silently reset to the largest allowable value given sep and max.len.

Value

A single string or an array of strings with the same length as strings.

Author(s)

Justin Hemann <support@causata.com>

See Also

abbreviate.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# only leading / trailing whitespace is removed
ShortenStrings(' abcdefghijklmnopqrstuvwxyz ', max.len=26)

# the middle is replaced with ...
ShortenStrings(' abcdefghijklmnopqrstuvwxyz ', max.len=20)

# the beginning is replaced with ...
# note that end.len is too long, it is silently set to 17 here.
ShortenStrings(' abcdefghijklmnopqrstuvwxyz ', max.len=20, end.len=20)

# the end is replaced with ...
ShortenStrings(' abcdefghijklmnopqrstuvwxyz ', max.len=20, end.len=0)

Causata documentation built on May 2, 2019, 3:26 a.m.