Javascript String extractString(startToken, endToken)

Description

Javascript String extractString(startToken, endToken)

/**//from   www  .ja  v  a2 s.com
 * Extracts the string value between the start token and end token
 * @param startToken
 * @param endToken
 * @returns the value between the start and end tokens or returns null
 */
String.prototype.extractString = function (startToken, endToken) {
    if (!this) {
        return null;
    }

    var idx = this.indexOf(startToken);
    if (idx < 0) {
        return null;
    }

    var endIdx = this.indexOf(endToken);
    if (endIdx < 0) {
        return null;
    }

    return this.substring(idx + startToken.length, endIdx);
};



PreviousNext

Related