简体   繁体   English

Javascript子字符串检查

[英]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. 我需要检查字符串是否包含130x130的大小。 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: 如果它返回除-1之外的任何内容,则找到该字符串:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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