最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How do I usein a JavaScript string without escaping? - Stack Overflow

programmeradmin3浏览0评论

I have a string that is automatically generated by some code that encodes a Google Static Map polyline set of longitude,latitude. However, it places these pesky backslashes in the string which tries to escape the character after it.

enc:{eggEhwnQDYOCZuDv@q@H}@v@k@^v@TQh@Aw@j@AJJ@CZKA?LNZ[RUEALDDCRC@AJBBCJ\FAEACC?GM?K@GDGDEJC@BDADBFB@F@HANGH?DB@D\W|@g@QIZm@I@YoAO

I am not putting the encode directly into the HTML (where it would be fine) but instead using JavaScript to do it so this polyline encode gets put into a variable like so:

mapcoords:"path=color:0x00000000|fillcolor:0xFF9999|enc:{eggEhw`nQDYOCZuDv@q@H}@v@k@^v@TQh@`Aw@j@AJJ@CZKA?LNZ[RUEALDDCRC@AJBBCJ\FAEACC?GM?K@GDGDEJC@BDADBFB@F@HANGH?DB@D\W|@g@QIZm@I@YoAO"

Any suggestions how I go around the escaping? I've looked for the ampersand symbol for backslash but it seems one does not exist (if it would even help). So I am not sure how else to go about this.

I have a string that is automatically generated by some code that encodes a Google Static Map polyline set of longitude,latitude. However, it places these pesky backslashes in the string which tries to escape the character after it.

enc:{eggEhwnQDYOCZuDv@q@H}@v@k@^v@TQh@Aw@j@AJJ@CZKA?LNZ[RUEALDDCRC@AJBBCJ\FAEACC?GM?K@GDGDEJC@BDADBFB@F@HANGH?DB@D\W|@g@QIZm@I@YoAO

I am not putting the encode directly into the HTML (where it would be fine) but instead using JavaScript to do it so this polyline encode gets put into a variable like so:

mapcoords:"path=color:0x00000000|fillcolor:0xFF9999|enc:{eggEhw`nQDYOCZuDv@q@H}@v@k@^v@TQh@`Aw@j@AJJ@CZKA?LNZ[RUEALDDCRC@AJBBCJ\FAEACC?GM?K@GDGDEJC@BDADBFB@F@HANGH?DB@D\W|@g@QIZm@I@YoAO"

Any suggestions how I go around the escaping? I've looked for the ampersand symbol for backslash but it seems one does not exist (if it would even help). So I am not sure how else to go about this.

Share Improve this question asked May 26, 2015 at 14:04 Christine268Christine268 7323 gold badges15 silver badges34 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

You have to escape the backslash with a backslash like this:

var some_string = "my string with a backslash here: \\ ";

Most editors today have a find/replace function that you can use to replace a single backslash with two backslashes. If you use Notepad++ you can use CTRL+H to access this function, but as I said, most recent editors and IDE's have this function.

All you need to do is escape the escape character, so you simply get \\ instead of a single \. You will have to do this replacement wherever it is you're outputting that string to the client.

发布评论

评论列表(0)

  1. 暂无评论