javascript match exact string -
how can check javascript if 1 string contains other string? have like:
var = "paris, france" var b = "paris.." a.match(b) //returns "paris, " should return null i think problem match uses regexp. there possibility allow sympols .,-/\ etc. ? thanks
to see if 1 string contains another, use string.indexof():
var str = 'paris, france'; var strindex = str.indexof('paris..'); if(strindex == -1) { //string not found } else { //string found } but, in case want have contains() function, can add string below:
if(!('contains' in string.prototype)) { string.prototype.contains = function(str, startindex) { return -1 !== string.prototype.indexof.call(this, str, startindex); }; } var str = 'paris, france'; var valid = str.contains('paris..'); if(valid) { //string found } else { //string not found }
Comments
Post a Comment