简体   繁体   中英

Javascript substring check

I am working with images, they all have their sizes mentioned in their name tag.

 http://mysite.com/audio/display%20image/130x130%20jpeg/5755285.jpg

I am getting those is an array of strings. I need to check if the string contains the size 130x130 in it. How can it be done?

var str = 'http://mysite.com/audio/display%20image/130x130%20jpeg/5755285.jpg';
var search = '130x130';

str.indexOf(search);

If it returns anything but -1 the string has been found:

if (str.indexOf(search) > -1) {
    // Your image contains 130x130
} else {
    // Your image does not contains 130x130
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM