Some Java Guy
Some Java Guy

Reputation: 5118

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?

Upvotes: 0

Views: 103

Answers (1)

SpaceBeers
SpaceBeers

Reputation: 13947

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
}

Upvotes: 2

Related Questions