quotes

Python “string_escape” vs “unicode_escape”

纵然是瞬间 提交于 2019-11-27 09:46:46
问题 According to the docs, the builtin string encoding string_escape : Produce[s] a string that is suitable as string literal in Python source code ...while the unicode_escape : Produce[s] a string that is suitable as Unicode literal in Python source code So, they should have roughly the same behaviour. BUT, they appear to treat single quotes differently: >>> print """before '" \0 after""".encode('string-escape') before \'" \x00 after >>> print """before '" \0 after""".encode('unicode-escape')

PHP quotes inside quotes

混江龙づ霸主 提交于 2019-11-27 09:44:27
Is it possible to put quotes inside quotes? If so how? Here is my code: <?php echo '<span onclick="$(this).addClass('selected');"> </span>'; ?> According to php.net To specify a literal single quote, escape it with a backslash (\). It means you could have: <?php echo '<span onclick="$(this).addClass(\'selected\');"> </span>'; ?> You could do this: <?php // some code ?> <span onclick="$(this).addClass('selected');"> </span> <?php // some more code. ?> Heredoc is the perfect solution for this: <?php echo <<< HereDocString <span onclick="$(this).addClass('selected');"> </span> HereDocString; ?>

How can I put quotes in a string?

二次信任 提交于 2019-11-27 09:29:29
I need to write a string literal to a text file, but the C# compiler finds errors when I use quote characters in it. My current code: writeText.WriteLine("<?xml version="1.0" encoding="utf-8"?>"); I need the output for the text file to be: <?xml version="1.0" encoding="utf-8"?> How can I put quote characters in strings in C#? You need to escape the quotation marks to put them in a string. There is two ways of doing this. Using backslashes in a regular string: writeText.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>"); Using double quoation marks in a @-delimited string: writeText

How to substitute quoted, multi-word strings as arguments?

只谈情不闲聊 提交于 2019-11-27 09:14:37
I'm trying to substitute a string variable, containing multiple quoted words, as a parameter to a command. Thus, given the following example script (Note the -x in the shebang, which causes the output to be logged to stderr), #!/bin/bash -x myArg="\"hello\" \"world\"" echo "string is:" $myArg exit Which gives us, + myArg='"hello" "world"' + echo 'string is:' '"hello"' '"world"' string is: "hello" "world" + exit Line two shows what is actually passed to the command; bash has added single quotes to each word in the string. If I instead, thusly, quote "$myArg", the same occurs but for the whole

python string adding backslash before single quotes

旧时模样 提交于 2019-11-27 08:49:01
问题 I have a string that contains quotes like this: string = "\"This is my mom's vase\", said Kevin." Problem is when I use it as a string in python it adds a backslash before single quotes, as seen here: >>> string '"This is my mom\'s vase", said Kevin.' >>> Why is this happening and what can I do about it? 回答1: It's just escaped in the repl. If you print it out, it will show there is no slash added: print(string) # output: "This is my mom's vase", said Kevin. 回答2: The Explanation What you're

Regex to match all unicode quotation marks

我的梦境 提交于 2019-11-27 08:36:56
问题 Is there a simple regular expression to match all unicode quotes? Or does one have to hand-code it like this: quotes = ur"[\"'\u2018\u2019\u201c\u201d]" Thank you for reading. Brian 回答1: Python doesn't support Unicode properties, therefore you can't use the Pi and Pf properties, so I guess your solution is as good as it gets. You might also want to consider the "false quotation marks" that are sadly being used - the acute and grave accent ( ´ and `` ): \u0060 and \u00B4`. Then there are

C++ CSV line with commas and strings within double quotes

主宰稳场 提交于 2019-11-27 08:05:16
问题 I'm reading a CSV file in C++ and the row format is as such: "Primary, Secondary, Third", "Primary", , "Secondary", 18, 4, 0, 0, 0 (notice the empty value) When I do: while (std::getline(ss, csvElement, ',')) { csvColumn.push_back(csvElement); } This splits up the first string into pieces which isn't correct. How do I preserve the string when iterating? I tried to do a combination of the above and while also grabbing the lines separated by double quote but I got wild results. 回答1: You need to

Get text in quotes

纵然是瞬间 提交于 2019-11-27 07:19:43
问题 is there is some function that can take just text inside the quotes from the variable? Just like: $text = 'I am "pro"'; echo just_text_in_quotes($text); I know that this function doesn't exist.. but I need something like that. I was thinking about fnmatch("*",$text) But this cant Echo just that text, It's just for check. Can you please help me? Thank you. 回答1: This function will return the first matched text between quotes (possibly an empty string). function just_text_in_quotes($str) { preg

Variable containing multiple args with quotes in Bash

岁酱吖の 提交于 2019-11-27 06:53:59
I generate a bash variable containing all my args and those args contain spaces. When I launch a command with those args - eg. ls $args - quotes are not correctly interpreted. Here is an example - also creating and erasing needed files. #!/bin/bash f1="file n1" f2="file n2" # create files touch "$f1" "$f2" # concatenate arguments args="\"$f1\" \"$f2\"" # Print arguments, then launch 'ls' command echo "arguments :" $args ls $args # delete files rm "$f1" "$f2" With that, I have some "no such file" errors for "file , n1" , "file and n2" You might consider using an array for the args, something

How to add single quote in the variable in Javascript?

给你一囗甜甜゛ 提交于 2019-11-27 06:40:25
问题 I have variable var str as following: var str = <option value="1">tea</option>; I would like to make it as below var quote_str = '<option value="1">tea</option>;' Is there anyone can help me? Thanks in advance! Edit: I have tried the following code,however, it's not correct. var quote_str = 'str'; 回答1: I think that you want the semicolon outside the string literal: var quote_str = '<option value="1">tea</option>'; If you mean that you want apostrophe characters inside the string also, you can