简体   繁体   English

如果字符串很奇怪,我该如何将字符串粘贴并分配给javascript变量?

[英]how do i paste and assign string to javascript variable, if string is weird?

This string is url part that comes after http://www.domain.com/?----this-part---- . 该字符串是http://www.domain.com/?----this-part----之后的url部分。

but my string is huge and it has quotes every now and then, single and double. 但是我的字符串很大,并且不时地带有单引号和双引号。 etc. 等等

Edit: originally i thought the quotes were messing it up but now it seems i was wrong. 编辑:本来我以为引号搞砸了,但现在看来我错了。 So i'm pasting whole string. 所以我要粘贴整个字符串。

https://gist.github.com/anonymous/21d40cabfc5252d1a7dd https://gist.github.com/anonymous/21d40cabfc5252d1a7dd

If the string is delimited by " You can replace " with \\" 如果字符串以"您可以用\\"替换"来定界

If the string is delimited by ' you can replace ' with \\' 如果字符串以'分隔,则可以将'替换为\\'

As an example: 举个例子:

var str = 'It\'s me';  // Is a string with the text It's me

If you take the string from the code is already a string so you don't need any modification. 如果您从代码中获取字符串,则已经是字符串,因此无需进行任何修改。

If you take the string from a copy from the browser url you can past it in an editor (notepad, ultraedit, vi, vim, leafpad...) and use the function "Replace" 如果您从浏览器URL的副本中获取字符串,则可以将其粘贴到编辑器中(记事本,ultraedit,vi,vim,leafpad ...),然后使用“替换”功能

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM