Created
July 6, 2016 06:20
-
-
Save tyoshikawa1106/9aefba696c67f4ec1f08f24474755e7a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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