quotes

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

巧了我就是萌 提交于 2019-11-26 17:58:48
问题 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 string/ %Q|"I'm acting like a double-quoted string" --Anonymous| I have not been working with Ruby for long, but I have never encountered this quoting method in production code. Other than the obvious ability to avoid internally escaping quotes with

How can I put quotes in a string?

点点圈 提交于 2019-11-26 17:50:58
问题 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#? 回答1: 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

Single quotes or double quotes for variable concatenation? [closed]

a 夏天 提交于 2019-11-26 17:45:03
Is it better to concatenate a variable (say, $name ) into an existing string (say, $string ) like this: $string='Hi, my name is '.$name or to embed the variable in the string like this: $string="Hi, my name is $name"; or is it better to use a function like this: $string=sprintf("Hi, my name is %s",$name); Which is better in terms of processor time/efficiency? Everyone who did the test concluded that using single quotes is marginally better performance wise. In the end single quotes result in just a concatenation while double quotes forces the interpreter to parse the complete string for

Finding quoted strings with escaped quotes in C# using a regular expression

依然范特西╮ 提交于 2019-11-26 17:29:51
I'm trying to find all of the quoted text on a single line. Example: "Some Text" "Some more Text" "Even more text about \"this text\"" I need to get: "Some Text" "Some more Text" "Even more text about \"this text\"" \"[^\"\r]*\" gives me everything except for the last one, because of the escaped quotes. I have read about \"[^\"\\]*(?:\\.[^\"\\]*)*\" working, but I get an error at run time: parsing ""[^"\]*(?:\.[^"\]*)*"" - Unterminated [] set. How do I fix this? What you've got there is an example of Friedl's "unrolled loop" technique, but you seem to have some confusion about how to express

Are there different types of double quotes in utf-8 (PHP, str_replace)?

回眸只為那壹抹淺笑 提交于 2019-11-26 17:13:04
问题 In PHP 5.3, am trying to replace double quotes in a string as such: $bar = str_replace('"','\'',$foo); But some quotes that are saved in the utf8-Database are not being replaced, although they look perfectly normal: "Some text" Are there different character types I have to search for? If so, which are they? 回答1: There are many characters that look like quotation marks, most of them are used infrequently. The ones that are used more often are these three: " U+0022 QUOTATION MARK “ U+201C LEFT

how to get data between quotes in java?

浪子不回头ぞ 提交于 2019-11-26 16:34:30
I have this lines of text the number of quotes could change like: Here just one "comillas" But I also could have more "mas" values in "comillas" and that "is" the "trick" I was thinking in a method that return "a" list of "words" that "are" between "comillas" How I obtain the data between the quotes? The result should be: comillas mas, comillas, trick a, words, are, comillas You can use a regular expression to fish out this sort of information. Pattern p = Pattern.compile("\"([^\"]*)\""); Matcher m = p.matcher(line); while (m.find()) { System.out.println(m.group(1)); } This example assumes

How to insert text with single quotation sql server 2005

喜夏-厌秋 提交于 2019-11-26 16:21:10
问题 I want to insert text with single quote Eg john's to table in sql server 2005 database 回答1: Escape single quote with an additional single as Kirtan pointed out And if you are trying to execute a dynamic sql (which is not a good idea in the first place) via sp_executesql then the below code would work for you sp_executesql N'INSERT INTO SomeTable (SomeColumn) VALUES (''John''''s'')' 回答2: The answer really depends on how you are doing the INSERT . If you are specifying a SQL literal then you

Why shouldn't `&apos;` be used to escape single quotes?

不问归期 提交于 2019-11-26 16:06:29
As stated in, When did single quotes in HTML become so popular? and Jquery embedded quote in attribute , the Wikipedia entry on HTML says the following: The single-quote character ('), when used to quote an attribute value, must also be escaped as ' or ' (should NOT be escaped as &apos; except in XHTML documents) when it appears within the attribute value itself. Why shouldn't &apos; be used? Also, is " safe to be used instead of " ? cletus " is on the official list of valid HTML 4 entities , but &apos; is not. From C.16. The Named Character Reference ' : The named character reference &apos;

bash alias command with both single and double quotes

限于喜欢 提交于 2019-11-26 15:42:10
问题 I have this command that does what I want but I can't get to alias it in my .bashrc (note that it uses both single and double quotes): svn status | awk '$1 =="M"{print $2;}' I've tried: alias xx="svn status | awk '$1 ==\"M\"{print $2;}'" And some other common sense combinations with no luck.. I know that bash is very picky with quotes.. So what's the correct way to alias it and why ? Thanks 回答1: You just need to escape it correctly. alias xxx="svn status | awk '\$1 ==\"M\"{print \$2;}'" 回答2:

Do I need quotes for strings in YAML?

拜拜、爱过 提交于 2019-11-26 15:37:52
I am trying to write a YAML dictionary for internationalization of a Rails project. I am a little confused though, as in some files I see strings in double quotes and in some without. A few points to consider: example 1 - all strings use double quotes; example 2 - no strings (except the last two) use quotes; the YAML cookbook says: Enclosing strings in double quotes allows you to use escapings to represent ASCII and Unicode characters. Does this mean I need to use double quotes only when I want to escape some characters? If yes - why do they use double quotes everywhere in the first example -