为什么字符串中的反斜杠()在控制台中出现错误

why backslash() in a string is giving error in console

本文关键字:控制台 错误 字符串 为什么      更新时间:2023-09-26

我有一个类似的字符串

"C:'projects'cisco'iwan_staging_enc'enterprise-network-controller'ui-plugins'iwan"

当我粘贴到console并按下回车键时,它会给出以下错误作为

Uncaught SyntaxError: Invalid Unicode escape sequence

怎么了

感谢

nageshwar

由于反斜杠是一个转义符,因此应该将字符串修改为:

"C:''projects''cisco''iwan_staging_enc''enterprise-network-controller''ui-plugins''iwan"

请参阅:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#Escape_notation

'u是unicode转义序列的开头,在字符串中有一个'u,后面没有四个十六进制数字,这是unicode escape序列'uxxxx的格式。参见

"C:'projects'cisco'iwan_staging_enc'enterprise-network-controller'u0050i-plugins'iwan"

'u0050 id P

还有其他类型的转义,所以例如,如果你在其中的某个地方有一个'n,你会得到一个换行

"C:'new projects'cisco'iwan_staging_enc'enterprise-network-controller'u0050i-plugins'iwan"

因此,如果您不想避免这些转义序列,请在字符串中的' s前面加一个斜杠。

"C:''projects''cisco''iwan_staging_enc''enterprise-network-controller''ui-plugins''iwan"