Skip to content

Instantly share code, notes, and snippets.

@ben-ng ben-ng/substr.js
Last active Mar 29, 2017

Embed
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
You can’t perform that action at this time.