A string interpolation within concatenation is producing two double quotes instead of one (JuliaLang) - string

I am trying to include a single double quote in a string during a concatenation within JuliaLang, as below:
tmpStr = string(tmpStr, string("graph [label=\" hi \"]; "))
The output in the text file written with writedlm is:
graph [label="" hi ""]
How can I modify the string interpolation to include only a single double quote instead of this repetition?

The extra double quotes come from writedlm. writedlm uses standard CSV escaping method, which surrounds special characters with double quotes, and uses "" to represent a single double quote. This is OK, as long as you do the inverse transformation when reading the file.
A good method to trace such problems is to create a minimal working example. In this case, something like:
writedlm("tst.tst",["\""])
Which writes tst.tst, but tst.tst now has:
""""
But when read properly:
julia> data = readdlm("tst.tst")
1×1 Array{Any,2}:
"\""
As expected.
Another option to avoid getting the extra quotes is to add quotes=false as an option to writedlm, as in the following example:
julia> writedlm(STDOUT,["\""],quotes=false)
"

Related

How to replace double quote character with single quote character in terraform

I'm running into a situation where i need terraform to replace this list with strings enclosed in single quotes like this. ['test1','test2']. How would i go about replacing a double quote character with a single quote character? I'm using the replace method, but getting an error when trying to replace with a single quote character. I believe terraform does not support single quotes. Another thing i would like is to create a new local that holds the string value "'test1','test2'", this is basically removing the square brackets.
locals {
appengineversions = ["test1","test2"]
appengine_instances_list = replace(local.appengine,'\"',"\'")
}
In your example, there is a list with two strings in it. Neither of those strings have any quotes in them. The value of the two strings are: test1 and test2. The double quotes in the code are Terraform syntax elements to denote the start and end of a string, they are not part of the actual string values.
So, I couldn't manage to print exactly ['test1','test2'] as you expected but somehow managed to replace double quotes with single quotes.
The reason, why you see double quotes is simply because it's for human readable purposes as mentioned here.
locals {
appengineversions = ["test1","test2"]
appengine_instances_list = format("['%s']", join("','", local.appengineversions))
}
output "test" {
value = local.appengine_instances_list
}
Terraform output ::
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
Outputs:
test = "['test1','test2']"
I used join & format functions here to convert list to string & then format accordingly.

Does a python string include the quotation marks?

For ('bobby'), is the string here 'bobby' or just bobby? I've tried to research into it but the other questions people ask are more complicated. I only want to know whether a full python string includes or doesn't include the '' marks.
If you are declaring a string, you need the quotation marks, like this example:
a = "Hello"
However, if you are just talking about the string itself, the quotations are not part of it. If I were to print variable a that I declared above, the output would be Hello, not "Hello".
print(a) -> Hello
A string is enclosed within the quotation mark, it does not mean that quotations are included in the string. The quotations are given just to tell the compiler that it is a string data type.
Ex -> "Hello"
'Hello'
But if you include double or single quotes inside single or double quotes in python respectively, then the inner quotation will be treated as a string.
Ex -> 'Ram said, "I love apples."'
"Ram said, 'I love apples.'"

' vs " " vs ' ' ' in Groovy .When to Use What?

I am getting really confused in Groovy. When to use what for Strings in Groovy ?
1) Single Quotes - ' '
2) Double Quotes - " "
3) Triple Quotes - '''
My code:
println("Tilak Rox")
println('Tilak Rox')
println('''Tilak Rox''')
All tend to produce same results.
When to Use What ?
I would confuse you even more, saying, that you can also use slash /, dolar-slash $/ and triple-double quotes """ with same result. =)
So, what's the difference:
Single vs Double quote: Most important difference. Single-quoted is ordinary Java-like string. Double-quoted is a GString, and it allows string-interpolation. I.e. you can have expressions embedded in it: println("${40 + 5}") prints 45, while println('${ 40 + 5}') will produce ${ 40 + 5}. This expression can be pretty complex, can reference variables or call methods.
Triple quote and triple double-quote is the way to make string multiline. You can open it on one line in your code, copy-paste big piece of xml, poem or sql expression in it and don't bother yourself with string concatenation.
Slashy / and dollar-slashy $/ strings are here to help with regular expressions. They have special escape rules for '\' and '/' respectfully.
As #tim pointed, there is a good official documentation for that, explaining small differences in escaping rules and containing examples as well.
Most probably you don't need to use multiline/slashy strings very often, as you use them in a very particular scenarios. But when you do they make a huge difference in readability of your code!
Single quotes ' are for basic Strings
Double quotes " are for templated Strings ie:
def a = 'tim'
assert "Hi $a" == 'Hi tim'
Triple single quotes ''' are for multi-line basic Strings
Triple double """ quotes are for multi-line templated strings
There's also slashy strings /hello $a/ which are templated
And dollar slashy Strings $/hello $a/$ which are multi-line and templated
They're all documented quite well in the documentation

Replace a char with double qoute

I am constructing json code syntax in a string. The format needs to be {"field":"somedata"} and so on. The problem is that I need to use a string and the code that I wrote is:
astring=astring + "{\"field\":\"somedata\"}"
The problem is that when I save the string as a textfile the backslashes is also saved and disqualifies this as json.
The I tried to use a diff char (a dog) as a replacement for \" and tried to replace the dog using:
res_str=res_str.stringByReplacingOccurrencesOfString("🐶", withString: "\"")
But the backslash was included. And finally I tried to
res_str=res_str.stringByReplacingOccurrencesOfString("🐶", withString: String(UnicodeScalar(34)))
But the backslash is included. In PHP for example I could have used single quote as outer string separator but that isn't allowed in Swift.
Any ideas?

How do I match a single double quote (") using excel vba's Like function?

I'm using excel's vba to match some numerical ratings. The rating can include a suffix:
+ add .25 to the rating
- subtract .25 from the rating
" add .50 to the rating
So for example if the rating: 5" would really mean 5.5 or 5+ would mean 5.25
I have a simple conditional:
if ActiveCell.Characters(i,1).Text Like [123456789+-"] then ...
Unfortunately the " produces an invalid character error. I've tried escaping as follows:
"""
'"'
\"
chr(34)
but can't seem to get the code to work. Thus, my question: How do you match a single double quote using excel VBA's Like function.
Use double quotes around Like, i.e.:
...Like "[-123456789+""]"...
Basically, when using Like, the regex is wrapped in double quotes and the double quote inside it is escaped with a second one.
Note that the - (hyphen) needs to be at the start or end of the regex, otherwise it denotes a range of characters. Thanks #ssarabando !

Resources