Skip to content

Instantly share code, notes, and snippets.

@tyoshikawa1106
Created July 6, 2016 06:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyoshikawa1106/9aefba696c67f4ec1f08f24474755e7a to your computer and use it in GitHub Desktop.
Save tyoshikawa1106/9aefba696c67f4ec1f08f24474755e7a to your computer and use it in GitHub Desktop.
String target = 'Helloooooooooooo!!';
String result = '';
// subString
result = target.substring(0, 5) + '...';
System.debug('subString : ' + result + ' (' + result.length() + ')');
// abbreviate
result = target.abbreviate(8);
System.debug('abbreviate : ' + result + ' (' + result.length() + ')');
// abbreviate
target = 'Helloooo';
result = target.abbreviate(8);
System.debug('abbreviate : ' + result + ' (' + result.length() + ')');
// abbreviate
target = 'Hi!';
result = target.abbreviate(8);
System.debug('abbreviate : ' + result);
// Null
try {
target = null;
result = target.substring(0, 5) + '...';
} catch (Exception e) {
System.debug('subString : ' + e.getMessage());
}
// Null
try {
target = null;
result = target.abbreviate(8);
} catch (Exception e) {
System.debug('abbreviate : ' + e.getMessage());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment