string-literals

Difference between string primitive and string wrapper object in Javascript [duplicate]

♀尐吖头ヾ 提交于 2019-12-08 09:12:30
问题 This question already has answers here : What's the point of new String(“x”) in JavaScript? (8 answers) Closed 4 years ago . I'm very confused about what the wrapper objects for primitives. For example, a string primitive and a string created with the string wrapper object. var a = "aaaa"; var b = new String("bbbb"); console.log(a.toUpperCase()); // AAAA console.log(b.toUpperCase()); // BBBB console.log(typeof a); // string console.log(typeof b); // object Both give access to String.prototype

c++: generating string literals from template parameters

拈花ヽ惹草 提交于 2019-12-07 03:48:04
问题 template < unsigned int i > struct t { static const char *s; }; template < unsigned int i > const char* t<i>::s = ...; where ... is "0 1 2 ... i-1", for example "0 1 2 3 4" for i == 5 . Is this possible? (no solutions doing this at run-time, please!) Question asked out of curiosity (doing it with preprocessor macros / constants would be easy, but how about template parameters)? The meaning is: compile-time generated string literal. I see now that const does not force this, but could take any

Quoting YAML (for Travis CI)

不羁的心 提交于 2019-12-06 21:14:43
问题 How would I escape a whole line in YAML? I want to have json='{"title": "travis_saulshanabrook_site","key": "'$(cat ~/.ssh/id_rsa.pub)'"}' in a list, but I can't get it to parse into a string. I can put single quotes around the whole line, but then I would have to escape every single quote in my string, making it very hard to read. The string will be run as a bash command in Travis CI 回答1: The most elegant solution is to use the literal style | indicator, with the - modifier to strip the

Raw literal strings in Julia

倖福魔咒の 提交于 2019-12-06 19:04:57
问题 In Python one can write r"a\nb" in order to prevent the \n from being interpreted as an escape sequence for newline. Is there something similar in Julia? And what about string interpolation like "$variable" , is there a way to prevent it? I know one can simply write "a\\nb" and "\$variable" in Julia, but I would like to write a lot of LaTeX strings without having to care to proper escape every backslash \ and dollar $ characters... (In Julia, r"..." creates a regular expression.) 回答1: From

Python convert string literals to strings

爷,独闯天下 提交于 2019-12-06 17:19:53
问题 I want to convert a string literal like r"r'\nasdf'" to a string ( '\\nasdf' in this case). Another case: r"'\nasdf'" to '\nasdf' . I hope you get it. This is important, because I have a parser of python scripts, that wants to know the exact contents of a string literal. Is eval a clever solution? The string literals are filtered before (with tokenize ) and should not cause security liabilities. Aren't there any nobler solutions than evaluating a literal? A parser library maybe? Edit : Added

How to use Golang custom scanner string literals and expand memory to load entire file into memory?

故事扮演 提交于 2019-12-06 06:02:37
问题 I have been trying to figure out how to implement what I originally thought would be a simple program. I have a text file of quotations that are all separated by ‘$$’ I want the program to parse the quotation file and randomly select 3 quotes to display and standard output. There are 1022 quotes in the file. When I attempt to split the file I get this error: missing ' I can’t seem to figure out how to assign $$ with a string literal, I keep getting: missing ' This is the custom scanner:

Address length of a string literal

独自空忆成欢 提交于 2019-12-06 02:08:52
I see that on Linux systems with GCC the address of string literals seems to be much smaller than for other variables. For instance the following code generates the o/p shown below it. #include <stdio.h> int main() { char *str1 = "Mesg 1"; char *str2 = "Mesg 2"; char str3[] = "Mesg 3"; char str4[] = "Mesg 4"; printf("str1 = %p\n", (void *) str1); printf("str2 = %p\n", (void *) str2); printf("&str3 = %p\n", (void *) str3); printf("&str4 = %p\n", (void *) str4); return 0; } Output: str1 = 0x400668 str2 = 0x40066f &str3 = 0x7fffcc990b10 &str4 = 0x7fffcc990b00 Is there a constant address space

Struct vs string literals? Read only vs read-write? [duplicate]

被刻印的时光 ゝ 提交于 2019-12-05 22:43:08
问题 This question already has answers here : Why are compound literals in C modifiable (2 answers) Why do I get a segmentation fault when writing to a string initialized with “char *s” but not “char s[]”? (17 answers) Closed last year . Does the C99 standard permit writing to compound literals (structs)? It seems it doesn't provide writing to literal strings. I ask about this because it says in C Programming: A Modern Approach, 2nd Edition on Page 406. Q. Allowing a pointer to a compound literal

C++ string literal equality check?

送分小仙女□ 提交于 2019-12-05 15:06:55
== is not how we compare two arrays, since that would only compare the addresses: #include <iostream> int main() { char a[] = "aaa"; char b[] = "aaa"; if (a == b) std::cout << "Yes" << std::endl; else std::cout << "No" << std::endl; return 0; } This code even gives me a warning: Array comparison always evaluates to false But when I tried this: if ("aaa" == "aaa") It seemed to be working fine. Still gives me a warning, but the warning is: Condition is always true At first, I thought it was some kind of caching thing, so I tried a rather unusual string literal: if ("whuiwhqohqweihqweohi" ==

Keeping code structure with string literal that uses whitespace

安稳与你 提交于 2019-12-05 09:14:56
问题 So a bit of a weird question I was having trouble coming up with the search terms for. If I have a multi-line string literal in my program, is there anyway to keep the indentation of my code consistent without adding unwanted white space to my string literal? Ex: if (true) { if (!false) { //Some indented code; stringLiteral = string.format( @"This is a really long string literal I don't want it to have whitespace at the beginning of each line, so I have to break the indentation of my program