Skip to content

Instantly share code, notes, and snippets.

@ben-ng
Last active March 29, 2017 18:28
Show Gist options
  • Save ben-ng/f1b0db0758621a24cf407c3c00b20373 to your computer and use it in GitHub Desktop.
Save ben-ng/f1b0db0758621a24cf407c3c00b20373 to your computer and use it in GitHub Desktop.
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