cut method
Cuts the String to the required length starting from the beginning
This method works approximately like the substring one, with the difference that, if the string length is lesser than the length required the string is returned unchanged instead of throwing error
Example: 'Cut This'.cut(3) returns 'Cut' 'Cut This'.cut(10) returns 'Cut This'
The method only works from the beginning of the string
Implementation
String cut(int newLength) {
if (length <= newLength) {
return this;
}
return substring(0, newLength);
}