Skip to content

Instantly share code, notes, and snippets.



Last active Mar 29, 2017
What would you like to do?
substr shim
// There is no String.substr on Salesforce. This uses String.substring instead.
// substring's arguments are different, so this just converts substr args to
// their substring equivalents.
function substrShim (str, start, len) {
if (len <= 0)
return '';
if (start < 0)
start = str.length + start;
if (len != null)
len = Math.min(str.length - 1, start + len);
return str.substring(start, len);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment