简体   繁体   English

如何检查字符串是否包含“?”标记

[英]How to check whether String contains “?” mark

I want to check whether string contains "?" 我想检查字符串是否包含“?” mark or not. 标记与否。 My string likes as " https://suort.mmo.com/jira/browse/AAA-157?fousedCommentId=120209&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-120209 " 我的字符串就像“ https://suort.mmo.com/jira/browse/AAA-157?fousedCommentId=120209&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-120209

I want to check this url string included "?" 我想检查包含“?”的URL字符串 mark or not using JavaScript. 标记或不使用JavaScript。

UPDATE: If you're using ES6, use String.prototype.includes : 更新:如果您使用的是ES6,请使用String.prototype.includes

const containsQuestionMark = myStr.includes('?');

Otherwise, if you're stuck on ES5, use indexOf 否则,如果您陷于ES5,请使用indexOf

var containsQuestionMark = myStr.indexOf('?') > -1;

check this site: 检查此站点:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf

the method indexOf returns -1 if it does not find the search term, so do this simple if statement 如果没有找到搜索词,则indexOf方法将返回-1,因此请执行以下简单的if语句

var s = 'string with a ? in it';

if(s.indexOf('?') != -1) { /* code if string has a ? */ }else{ /*code if string does not have a ? */ }

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

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