quotes

How to remove unwanted single quotes

孤人 提交于 2019-12-02 07:44:09
I'm new to programming and I stumbled across something unsightly that I would like to remove. Here's my code: def test1(): print "What is your name, traveler?" name = raw_input() print "Hi %r!" % (name) Here's the output: What is your name traveler? Hi 'Karatepig'! Is there any way to get rid of those single quotes around my name? ron rothman You want to use %s there, not %r . print "Hi %s!" % (name) I'd add details, but I think others have already written better explanations here and here . Most saliently: The difference between %s and %r is that %s uses the str function and %r uses the repr

How to make variables work in Single Quotes properly?

一笑奈何 提交于 2019-12-02 07:34:40
I want those variables to be filled with their values, but in config.php file its writing the variable name itself, I want like $host convert to 'localhost' with single quotes in the config.php file. $handle = fopen('../config.php', 'w'); fwrite($handle, ' <?php $connection = mysql_connect({$host}, {$user}, {$pass}); ?> '); fclose($handle); If you use variables within single quotes, they will be represented as strings instead of variables. You can also do it like this: // Get from $_SESSION (if started) $host = $_SESSION['host']; $user = $_SESSION['user']; $pass = $_SESSION['pass']; $handle =

PHP: Work with a large string with quotes

╄→гoц情女王★ 提交于 2019-12-02 05:32:19
Suppose I have a large string of HTML code. It has both double quotes and single quotes. How can I work with such a string? I want to assign it to a php var but there's a quote clash whether I use double quotes or single quotes. Is there any way to assign this string to a var without having to manually add slashes to all the quotes? It could be something like this: <div class="name">Sally O'Connel</div> Only the string is longer so there will be multiple occurances of single quotes and double quotes. You could use HEREDOC/NOWDOC : $var = <<<HTML <div class="name">Sally O'Connel</div> HTML;

Bash: pass variable as a single parameter / shell quote parameter

不羁岁月 提交于 2019-12-02 05:25:03
问题 I'm writing a bash script which has to pass a variable to another program: ./program $variable The problem is, it is absolutely necessary for $variable to be passed as a single parameter, which isn't the case if it contains whitespace. variable=Hello World ./program $variable -> program receives two arguments: 'Hello' 'World' Quoting it doesn't do anything at all (well done, bash devs): variable=Hello World ./program "$variable" -> program receives: 'Hello' 'World' Double quoting it does

Replacing quotation marks with “``” and “''”

試著忘記壹切 提交于 2019-12-02 05:10:31
问题 I have a document containing many " marks, but I want to convert it for use in TeX. TeX uses 2 ` marks for the beginning quote mark, and 2 ' mark for the closing quote mark. I only want to make changes to these when " appears on a single line in an even number (e.g. there are 2, 4, or 6 " 's on the line). For e.g. "This line has 2 quotation marks." --> ``This line has 2 quotation marks.'' "This line," said the spider, "Has 4 quotation marks." --> ``This line,'' said the spider, ``Has 4

How to replace ' with empty string in Java

﹥>﹥吖頭↗ 提交于 2019-12-02 04:19:43
How can I replace single quote ' with empty string in Java. I tried following but doesn't seem to be working. String data="Sid's den"; data.replace("'", ""); data.replaceAll("'", ""); Thanks in advance. Any help is much appreciated.(Output should be: Sids den) Thanks guys for your responses. I guess I should have been more clear about my question. Basically I am getting special characters from the table and with what value we have to replace that also from the same table. Here is snippet of the code: query = "select spl_char, replace_with from entcon_splchars"; ptsmt = DBConnector

Why string with single quotes raises error when inserted in DB?

☆樱花仙子☆ 提交于 2019-12-02 03:40:58
问题 My question is: How do you allow single quotes in strings? For example, I have a form, and a text box. It is set up to allow the user to enter their name. From there, it posts and feeds the data into a database. I need to be able to allow single quotes (apostrophe) as some people's names have an apostrophe in their names, such as "O'Reilly". Any suggestions? 回答1: Single quotes are not forbidden in any way. I'll simply assume that you got an error inserting it into the database. This is likely

Bash: pass variable as a single parameter / shell quote parameter

穿精又带淫゛_ 提交于 2019-12-02 01:21:50
I'm writing a bash script which has to pass a variable to another program: ./program $variable The problem is, it is absolutely necessary for $variable to be passed as a single parameter, which isn't the case if it contains whitespace. variable=Hello World ./program $variable -> program receives two arguments: 'Hello' 'World' Quoting it doesn't do anything at all (well done, bash devs): variable=Hello World ./program "$variable" -> program receives: 'Hello' 'World' Double quoting it does crazy stuff (well done, bash devs): variable=Hello World ./program "'$variable'" -> program receives: "

php - convert single quoted string to double quoted

一笑奈何 提交于 2019-12-02 00:21:18
问题 Been searching here and google for over an hour, can't seem to find the answer to this. I have a string returned from a database query which contains variables, however it appears that these strings are all returned single-quoted and therefore the variables are not evaluated as they would be if it was double quoted. what is returned from the sql query would be the $result: This will not evaluate the 2 variables: $myname = 'david'; $occupation = 'Beginner'; $result = 'Hello my name is $myname

Why string with single quotes raises error when inserted in DB?

廉价感情. 提交于 2019-12-01 23:42:45
My question is: How do you allow single quotes in strings? For example, I have a form, and a text box. It is set up to allow the user to enter their name. From there, it posts and feeds the data into a database. I need to be able to allow single quotes (apostrophe) as some people's names have an apostrophe in their names, such as "O'Reilly". Any suggestions? Single quotes are not forbidden in any way. I'll simply assume that you got an error inserting it into the database. This is likely due to the omission of mysql_real_escape_string() on input values. You will get an SQL error if you try