String.ellipsis

Syntax

PP.String.ellipsis(value: String, length: Number, word: Boolean);

Parameters

value. Source string to clip.

length. Maximum string length. Parameter value cannot be less than 3 or greater than length of the source string.

word. Indicates if to account for string right border. If this parameter is set to True, the string characters after separator (fraction part of a number) is ignored, otherwise (default) - it is accounted for. Optional parameter.

Description

The ellipsis static method clips a string to a certain length.

Comments

This method returns a String-type value.

Example

To execute the example, add a link to PP.js scenario file to HTML page. Clip the source string to 10 characters considering and ignoring the right border, next extend it to 15 characters:

// Set a source string
var pi = "31415.926535";
console.log("Source string: " + pi);
// Cut the source string by 10 characters from the left
console.log("Cut string without taking into account the right border: " +
    PP.String.ellipsis(pi, 10, False));
console.log("Cut string with taking into account the right border: " +
    PP.String.ellipsis(pi, 10, True));
// Extend the string to 15 characters
console.log("String extended to 15 characters: " +
    PP.String.leftPad(pi, 15, '`'));

After executing the example the source string is clipped to 10 characters ignoring and accounting for the right border, and then expanded to 15 characters. The results of operation are shown in the browser console:

Source string: 31415.926535

Clipped string ignoring the right border: 31415.9...

Clipped string accounting for the right border: 31415...

String expanded to 15 characters: ```31415.926535

See also:

PP