Parts
Processing parts of a String
Strings allow you to work with parts of a String, splitting or joining a string.
abbreviate
The abbreviate method truncates a string to 'maxWidth' characters and adds '...' to the end.
The maxWidth argument sets the maxWidth of the resulting String, including the trailing ellipsis (...).
You can use the 'offset' argument to control where the truncation starts from.
If the 'string' is shorter than 'maxWidth' then the string is returned without change.
If you pass null then 'string' will be treated as a zero length string.
Extension
The abbreviate
method is available as an extension method on the String class.
hidePart
The 'hidePart' method replaces a section of the string with replacement character.
This can be used to hide a security token or a password contained within a string.
To hide a section of the string define a start
position (defaults to 0) and an end
position (defaults to the end of the string). The start
position is inclusive and the end
exclusive (just like substring).
Be default the replacement string is '*' but you can modify the value by passing an alternate string to replaceWith
. replaceWith
is normally a single character but it can be any String.
extension
The hidePart
method is available as an extension method on the String class;
join
The 'join' method concatenates a list of objects into a String by calling their 'toString' method, separating each item with the separator.
If the 'list' is null an empty String is returned;
If any member of the list is null then just the separator is output for that element.
left
The left method returns the left 'n' characters from a string.
If the String is less than the 'length' passed then you can optionally pad the String to 'length' characters long.
By default, no padding will be applied (Pad.none).
If you pass null then it will be treated as a zero length String.
extension
The 'left' method is available as an extension method on the String class.
right
The right method returns the right 'n' characters from a string.
If the String is less than the 'length' passed then you can optionally pad the String to 'length' characters long.
By default, no padding will be applied (Pad.none).
If you pass null then it will be treated as a zero length String.
extension
The 'right' method is available as an extension method on the String class.
Last updated