简体   繁体   中英

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---- .

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

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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