javascript - why backslash() in a string is giving error in console - Stack Overflow

i have a string like "C:projectsciscoiwan_staging_encenterprise-network-controllerui-plugins

i have a string like

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

when i paste into console and press enter, it is giving following error as

Uncaught SyntaxError: Invalid Unicode escape sequence

whats wrong here

Thanks

nageshwar

i have a string like

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

when i paste into console and press enter, it is giving following error as

Uncaught SyntaxError: Invalid Unicode escape sequence

whats wrong here

Thanks

nageshwar

Share Improve this question asked Aug 2, 2016 at 13:47 Nageshwar Reddy PandemNageshwar Reddy Pandem 1,0479 silver badges15 bronze badges 4
  • The \backslash is an escape character. – gcampbell Commented Aug 2, 2016 at 13:49
  • means i didnt get you – Nageshwar Reddy Pandem Commented Aug 2, 2016 at 13:50
  • you need to use two backslashes for it to be accepted as a backslash: developer.mozilla/en-US/docs/Web/JavaScript/Reference/… – Arathi Sreekumar Commented Aug 2, 2016 at 13:50
  • @NageshwarReddy developer.mozilla/en-US/docs/Web/JavaScript/Reference/… – gcampbell Commented Aug 2, 2016 at 13:51
Add a ment  | 

2 Answers 2

Reset to default 3

Since backslash is an escape character your string should be modified to:

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

Please see: https://developer.mozilla/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#Escape_notation

The \u is the start of a unicode escape sequence, in your string you have a \u not followed by four hex numbers which is the format of unicode escape sequence \uxxxx. See

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

\u0050 id P

Also there there are other types of escapes, so for instance if you had a \n somewhere in there you would get a newline

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

So if you do not want avoid these escape sequences escape the \s in the string with a slash before it.

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744660860a4586454.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信