I've always used double quotes when dealing with variables in functions. Like this function %my_usr_var% = $left($proper($alrep("%s_original_name%","")),28) to shorten and remove spaces etc from filenames in a populate variable node.
Ran into some issues with using the $jsonencode function to create a JSON friendly version of %s_error%. For the below examples assume "%s_error%" is equal to Youtube-dl@HOSTEN250-04: Could not download: "swarm shake 2019.mp4"
My initial attempt was this
%json_error% = $jsonencode("%s_error%") but the value of %json_error% became $jsonencode("Youtube-dl@HOSTEN250-04: Could not download: "swarm shake 2019.mp4"") which is not JSON friendly.
When I changed it to single quotes
%json_error% = $jsonencode('%s_error%') the value of %json_error% became Youtube-dl@HOSTEN250-04: Could not download: \"swarm shake 2019.mp4\" which is correct.
Looking for insight on when to use single ' quotes vs double " quotes. I want to go through my variable nodes and make sure they are correct.
[SOLVED] Functions question...when to use double vs single quotes?
-
- Posts: 106
- Joined: Wed Dec 27, 2017 3:21 am
[SOLVED] Functions question...when to use double vs single quotes?
Last edited by crispyjones on Fri Jun 26, 2020 6:51 pm, edited 1 time in total.
Re: Functions question...when to use double vs single quotes?
Hey crispy,
very good question, this might give you some more insight:
https://www.autoitscript.com/forum/topi ... le-quotes/
Basically it says, use single quotes when your text contains double quotes and vice-versa.
If i am not wrong, you always use double quotes for filenames because they cannot contain one. But for larger text it gets a little tricky... @admin might tell us a little more about it and we should also mention this in the wiki
very good question, this might give you some more insight:
https://www.autoitscript.com/forum/topi ... le-quotes/
Basically it says, use single quotes when your text contains double quotes and vice-versa.
If i am not wrong, you always use double quotes for filenames because they cannot contain one. But for larger text it gets a little tricky... @admin might tell us a little more about it and we should also mention this in the wiki
emcodem, wrapping since 2009 you got the rhyme?
Re: Functions question...when to use double vs single quotes?
Hi cripsyjones,
If your literal string does NOT contain neither double nor single quotes it really does not matter. For example:
"%s_my_variable" is just as good as '%s_my_variable'. On the other hand:
"my "string" is cool" and 'my 'string' is cool' will NOT work.
If you are usure or you string contains mixed quotes, you should store the string in a variables before using it in a function.
Hope this helps.
-steinar
If your literal string does NOT contain neither double nor single quotes it really does not matter. For example:
"%s_my_variable" is just as good as '%s_my_variable'. On the other hand:
"my "string" is cool" and 'my 'string' is cool' will NOT work.
If you are usure or you string contains mixed quotes, you should store the string in a variables before using it in a function.
Hope this helps.
-steinar
-
- Posts: 106
- Joined: Wed Dec 27, 2017 3:21 am
Re: Functions question...when to use double vs single quotes?
Because this is an error reporting block it's hard to guess what might be in the %s_error% string. I tested your solution for mixed quotes, I was skeptical, but it worked (at least on my error containing double quotes)! Thank you.