三種方法:find()
,count()
,in
string_1 =
input
('1st string: '
)string_2 =
input
('2nd string: '
)# 方法一:使用find()
# 如果字串1包含字串2,返回字串2在1中的起始索引
# 如果不包含,則返回❀'-1'❀
(string_1.find(string_2)
)# 方法二:使用count()
# 若出現,返回出現次數;若未出現,返回0
(string_1.count(string_2)
)# 方法三:使用in
# 返回值為'true'或'false'
(string_2 in string_1)
js 字串是否包含某個字元
方法一 indexof 推薦 var str 123 console.log str.indexof 3 1 trueindexof 方法可返回某個指定的字串值在字串中首次出現的位置。如果要檢索的字串值沒有出現,則該方法返回 1。方法二 search var str 123 console.log ...
js 判斷字串是否包含某個字元
方法一 indexof 推薦 var str 123 console.log str.indexof 3 1 trueindexof 方法可返回某個指定的字串值在字串中首次出現的位置。如果要檢索的字串值沒有出現,則該方法返回 1。方法二 search var str 123 console.log ...
mysql 字段判斷是否包含某個字串
select id,learn plan id,sequence,is valid,support goods level from qs study subject plan configuration where is valid 1 and learn plan id 3 and find i...