Checks if current string contains the given sub-string. - Node.js String

Node.js examples for String:Parse

Description

Checks if current string contains the given sub-string.

Demo Code

/*******************************************************************************
 * Copyright (c) 2012 eBay Inc. and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*w w w  .  j ava 2 s . co  m*/
 *     eBay Inc. - initial API and implementation
 *******************************************************************************/
//@Package org.eclipse.vjet.vsf.typeextensions.string
/**
* Checks if current string contains the given sub-string.
* 
* @param {String} str
*        a sub-string to be tested
* @return {boolean}
*        <code>true</code> if the sub-string is in the current string
*/

String.prototype.has = function (pStr) { 
  return (this.indexOf(pStr) != -1); 
};

Related Tutorials