Js function when passing parameters, if the parameters of the path type, comprising inside: '\' character error

In the function, the parameters passed in the "\" character, js it will default to escape a string, the string if escaped with his match does not appear, will be missing, for example:

Such a string as a parameter: C: \ Program Files (x86) \ MySQL \ MySQL Server 5.7 \ data \

The value passed to the function inside will be converted to default: C: Program Files (x86) MySQLMySQL Server 5.7data

If you want to achieve precise pass this parameter, you need to string processing, generally have two ways:

  ①: string inside '\' character replaced with '/' so as not to be escaped

  ②: string inside '\' character replaced with '\\' character, this is also possible values ​​= value.split ( '\\') join ( '\\\\').

 

There is also a pit: the rear end of the string is returned is: C: \ Program Files (x86) \ MySQL \ MySQL Server 5.7 \ data \ use console.log to print out properly; however, their definition of a string assignment is: C: \ Program Files (x86) \ MySQL \ MySQL Server 5.7 \ data \ this string is out of print

Guess you like

Origin www.cnblogs.com/kdiekdio/p/12175270.html