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

Node.js examples for String:Parse

Description

Checks if current string contains the given arguments.

Demo Code

/**/*from  w w w  . java2 s .  c o  m*/
* Checks if current string contains the given arguments.
* @param {String} arg
*        a given arguments object. This can be a single string or a string array.
* @return {boolean}
*        <code>true</code> if the arguments is in the current string
*/
String.prototype.hasArg = function (pArg) {
  var a = pArg, rv = false;
  if (typeof(a) == "string")
  {
    rv = this.has(a);
  }
  else{
    var aL = a.length;
    for (var j=0; j<aL && !rv; j++)
    {
      rv = this.has(a[j]);
    }
  }
  return rv;
};
/*******************************************************************************
 * 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:
 *     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