gpt4 book ai didi

javascript - 切换大小写以检查字符串是否包含子字符串

转载 作者:行者123 更新时间:2023-12-04 10:34:36 26 4
gpt4 key购买 nike

我有一个字符串,想检查是否有带有 switch/case 的子字符串。 fnstringCheck 返回 true例如,如果 fnstring 是 dies_ist_ein_test_diagnosen_erfassen .

怎么了?谢谢你的提示

 var fnstring = (interim_transcript).toLowerCase().replace(/ /gi, "_");

console.log('fnstring:', fnstring)
var fnstringCheck = fnstring.indexOf("diagnosen_erfassen") !== -1;
console.log(fnstringCheck)

switch (fnstring) {
case (fnstring.indexOf("_arztbrief_analysieren") !== -1):
$('.analyzesBtn').trigger('click');
break;

case (fnstring.indexOf("_einleitung_erfassen") !== -1):
changeSection('einleitung', mergedSource);
break;

case (fnstring.indexOf("diagnosen_erfassen") !== -1):
changeSection('einleitung', mergedSource);
break;

...

最佳答案

您需要带true switch statement ,因为案例返回 truefalse .该支票使用 Identity/strict equality operator === .

var fnstring = (interim_transcript).toLowerCase().replace(/ /gi, "_");

console.log('fnstring:', fnstring)
var fnstringCheck = fnstring.indexOf("diagnosen_erfassen") !== -1;
console.log(fnstringCheck)

switch (true) { // strict comparison
case fnstring.indexOf("_arztbrief_analysieren") !== -1:
$('.analyzesBtn').trigger('click');
break;

case fnstring.indexOf("_einleitung_erfassen") !== -1:
changeSection('einleitung', mergedSource);
break;

case fnstring.indexOf("diagnosen_erfassen") !== -1:
changeSection('einleitung', mergedSource);
break;
}

关于javascript - 切换大小写以检查字符串是否包含子字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60247702/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com