Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/377.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 将提示符与unicode匹配_Javascript - Fatal编程技术网

Javascript 将提示符与unicode匹配

Javascript 将提示符与unicode匹配,javascript,Javascript,我试图编写一个脚本,提示输入字符串,并提醒输入的字符串是否包含反斜杠或泰卢古字母“ddha”(U+0C22) 这是我的代码: string = prompt("Enter a string") emoji = fixFromCharCode(U+0C22); if (string === "/") { alert("There is a / in the string"); } else (string === emoji) { alert("There is a " + e

我试图编写一个脚本,提示输入字符串,并提醒输入的字符串是否包含反斜杠或泰卢古字母“ddha”(U+0C22)

这是我的代码:

string = prompt("Enter a string")
emoji = fixFromCharCode(U+0C22); 

if (string === "/") {
    alert("There is a / in the string");
} else (string === emoji) {
    alert("There is a " + emoji + " in the string")
}

我收到“意外令牌非法”错误。如何将提示与Unicode匹配?

替换
emoji=fixFromCharCode(U+0C22)带有
emoji=fixFromCharCode(“\u0c22”)

尝试以下操作:

string = prompt("Enter a string")
emoji = String.fromCharCode(3106);  // decimal value of 0C22 

if (string === "/") {
    alert("There is a / in the string");
} else if(string === emoji) {
    alert("There is a " + emoji + " in the string")
}
注意:编辑此项可将字符代码更改为十进制表示形式

还请注意,您的文本描述了查找反斜杠,但您的代码检查了正斜杠

而且。。。上面以固定格式显示的代码检查是否有一个字符串正好等于“/”或“表情符号”。您的问题陈述是“contains”。因此,如果您想检测类似“此字符串中有一个/”之类的内容,则需要做更多的工作。我认为这样可以做到:

string = prompt("Enter a string")
emoji = String.fromCharCode(3106);  // decimal value of 0C22 

if (string.indexOf("/") > -1) {     // Checks for "contains" instead of equals
    alert("There is a / in the string");
} else if (string.indexOf(emoji) > -1) {
    alert("There is a " + emoji + " in the string")
}

@这是javascript。我请求删除java标记,因为这很混乱。似乎不需要标记
java