[SOLVED] Functions question...when to use double vs single quotes?

Questions and answers on how to get the most out of FFAStrans
Post Reply
crispyjones
Posts: 51
Joined: Wed Dec 27, 2017 3:21 am

[SOLVED] Functions question...when to use double vs single quotes?

Post by crispyjones » Wed Jun 24, 2020 4:15 pm

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.
Last edited by crispyjones on Fri Jun 26, 2020 6:51 pm, edited 1 time in total.

emcodem
Posts: 629
Joined: Wed Sep 19, 2018 8:11 am

Re: Functions question...when to use double vs single quotes?

Post by emcodem » Wed Jun 24, 2020 6:52 pm

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

admin
Site Admin
Posts: 1446
Joined: Sat Feb 08, 2014 10:39 pm

Re: Functions question...when to use double vs single quotes?

Post by admin » Thu Jun 25, 2020 7:19 am

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

crispyjones
Posts: 51
Joined: Wed Dec 27, 2017 3:21 am

Re: Functions question...when to use double vs single quotes?

Post by crispyjones » Fri Jun 26, 2020 6:50 pm

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.
populateVar.jpg
populateVar.jpg (81.33 KiB) Viewed 283 times

Post Reply