2013年8月1日 星期四

JavaScript search() 方法

String.search

 example

var stringValue = "This is my test string to search";
var result = stringValue.search(/is|test|string/);
//if () {....} 
//true return 6 false return -1
var str = "This is a sample text";
var re = /nothing|text|string/g
if (str.search(re) != -1) {
    midstring = " contains ";
} else {
    midstring = " does not contain ";
}

沒有留言: