Questions tagged [quotes]

Computer programming languages' facility for embedding text in source code, also known as String literals

In plain English: String literals can be enclosed in matching single quotes (') or double quotes (").

References:

2134 questions
107
votes
10 answers

How to remove extra indentation of Python triple quoted multi-line strings?

I have a python editor where the user is entering a script or code, which is then put into a main method behind the scenes, while also having every line indented. The problem is that if a user has a multi line string, the indentation made to the…
Mike
95
votes
3 answers

How does the leading dollar sign affect single quotes in Bash?

I need to pass a string to a program as its argument from the Bash CLI, e.g program "don't do this" The string may include any character like '$', '\', etc. and I don't want Bash to do any modification. So I think about using single quotes. However…
user1206899
  • 1,564
  • 1
  • 11
  • 15
85
votes
5 answers

bash regex with quotes?

The following code number=1 if [[ $number =~ [0-9] ]] then echo matched fi works. If I try to use quotes in the regex, however, it stops: number=1 if [[ $number =~ "[0-9]" ]] then echo matched fi I tried "\[0-9\]", too. What am I…
tpk
  • 2,041
  • 5
  • 21
  • 29
82
votes
5 answers

Escaping Strings in JavaScript

Does JavaScript have a built-in function like PHP's addslashes (or addcslashes) function to add backslashes to characters that need escaping in a string? For example, this: This is a demo string with 'single-quotes' and "double-quotes". ...would…
Steve Harrison
  • 121,227
  • 16
  • 87
  • 72
77
votes
7 answers

Dealing with quotes in Windows batch scripts

In a Windows batch file, when you do the following: set myvar="c:\my music & videos" the variable myvar is stored with the quotes included. Honestly I find that very stupid. The quotes are just to tell where the string begins and ends, not to be…
GetFree
  • 40,278
  • 18
  • 77
  • 104
76
votes
4 answers

Regex to match all instances not inside quotes

From this q/a, I deduced that matching all instances of a given regex not inside quotes, is impossible. That is, it can't match escaped quotes (ex: "this whole \"match\" should be taken"). If there is a way to do it that I don't know about, that…
Azmisov
  • 6,493
  • 7
  • 53
  • 70
74
votes
9 answers

Is there any difference between "string" and 'string' in Python?

In PHP, a string enclosed in "double quotes" will be parsed for variables to replace whereas a string enclosed in 'single quotes' will not. In Python, does this also apply?
davidmytton
  • 38,604
  • 37
  • 87
  • 93
74
votes
5 answers

What is the use case for Ruby's %q / %Q quoting methods?

I've been reading through Thomas' Programming Ruby 1.9 and came upon the alternative delimited single and double-quoting methods (%q / %Q). I've known of them from other Ruby language references as well. %q/I'm acting like a single-quoted…
Michael Berkowski
  • 267,341
  • 46
  • 444
  • 390
68
votes
4 answers

Why doesn't Python give any error when quotes around a string do not match?

I've started learning Python recently and I don't understand why Python behaves like this: >>> "OK" 'OK' >>> """OK""" 'OK' >>> "not Ok' File "", line 1 "not Ok' ^ SyntaxError: EOL while scanning string literal >>> "not…
W. R.
  • 822
  • 4
  • 6
65
votes
11 answers

Remove quotes from a character vector in R

Suppose you have a character vector: char <- c("one", "two", "three") When you make reference to an index value, you get the following: > char[1] [1] "one" How can you strip off the quote marks from the return value to get the following? [1] one
Milktrader
  • 9,278
  • 12
  • 51
  • 69
65
votes
2 answers

How do I remove quotes from a string?

$string = "my text has \"double quotes\" and 'single quotes'"; How to remove all types of quotes (different languages) from $string?
James
  • 42,081
  • 53
  • 136
  • 161
63
votes
18 answers

Regex to split a CSV

I know this (or similar) has been asked many times but having tried out numerous possibilities I've not been able to find a a regex that works 100%. I've got a CSV file and I'm trying to split it into an array, but encountering two problems: quoted…
Code Ninja
  • 727
  • 1
  • 7
  • 9
62
votes
14 answers

Write CSV To File Without Enclosures In PHP

Is there a native function or solid class/library for writing an array as a line in a CSV file without enclosures? fputcsv will default to " if nothing is passed in for the enclosure param. Google is failing me (returning results for a whole bunch…
Derek Reynolds
  • 3,473
  • 3
  • 25
  • 34
62
votes
5 answers

Having trouble escaping quotes and braces

I am trying to execute the following line in Command Prompt: curl -X POST -d '{ "method" : "account_info", "params" : [ { "account" : "rHb9CJAWyB4rj91VRWn96DkukG4bwdtyTh"} ] }' http://s1.ripple.com:51234 However, I get the following: curl: (6)…
killajoule
  • 3,612
  • 7
  • 30
  • 36
60
votes
6 answers

MacOSX: how to disable accented characters input

I'm using Eclipse Juno on MacOSX Lion and have an issue with typing. I often print one quote/apostrophe and move the caret. But in this Mac version of Eclipse the quote as I type is highlighted by orange marker (it seems like Mac smart quotes…
Tertium
  • 6,049
  • 3
  • 30
  • 51