开发者

if(string.Contains(string)). Is that possible?

开发者 https://www.devze.com 2023-02-07 11:45 出处:网络
I am trying to check if a string is contained in another string.Code behind is pretty straight forward.How can I do t开发者_运维百科hat in jquery?

I am trying to check if a string is contained in another string. Code behind is pretty straight forward. How can I do t开发者_运维百科hat in jquery?

function deleteRow(locName, locID) {
    if(locName.Contains(locID)) {
        alert("success");
    }
}


Use String.prototype.indexOf

For example: (locName.indexOf(locID) > -1)

String.prototype.contains doesn't exist.


You can use the indexOf method of the string. If you really want the convenience of having a contains method, you could add one to String.prototype:

String.prototype.contains = function(str) {
    return this.indexOf(str) > -1;
};

alert("foobar".contains("oob")); // true
alert("foobar".contains("baz")); // false


you can use indexOf if the string is found returned result will be different from -1

function deleteRow(locName, locID) {
    if(locName.indexOf(locID) != -1) {
        alert("success");
    }
}

I hope this helps

0

精彩评论

暂无评论...
验证码 换一张
取 消