string-literals

strcat(dest, “\something”) - backslash not showing

孤人 提交于 2019-12-12 04:58:02
问题 I got a problem with C programming string concatenation. Why strcat(dest, "\something") will not have the backslash copied to dest ? You may wish to follow the example. #include <stdio.h> #include <stdlib.h> #include <string.h> int main() { char *dest = ""; char *test = "how \something"; dest = (char *)malloc((strlen(test) + 1) * sizeof(char)); strcat(dest, test); // Expect to see "how \something", but showed "how something" printf("%s\n", dest); free(dest); return 0; } 回答1: backslash not

Optimizing flex string literal parsing

孤街浪徒 提交于 2019-12-12 03:34:03
问题 I am starting writing a lexical analyzer for my programming language. String literals in this language start with a " and end when an unescaped " is encountered. Everything inside (including newlines) is preserved, except escape sequences (the usual \n s, \t s, \" s etc plus a way of escaping a character by using its ASCII code, e.g. \097 or \97 ). This is the code I have written so far: %{ #include <iostream> #define YY_DECL extern "C" int yylex() std::string buffstr; %} %x SSTATE %% \" {

Does use of new String(“hello”) is completely useless over simple “hello”, when it is indirectly pointing to “hello”?

雨燕双飞 提交于 2019-12-12 02:39:49
问题 After executing String S1 = "hello"; JVM will create a String object in SCP and that object will hold an array of char in value field like s1.value = {'h', 'e', 'l', 'l', 'o'} And when we say String s2 = new String("hello"); And according to the source code of String class after constructor execution s2.value will also become "hello".value which will be similar to s1.value . public String(String original) { this.value = original.value; this.hash = original.hash; } So every time we create

Lambda string as VARCHAR

橙三吉。 提交于 2019-12-12 01:34:53
问题 One of my Join key-selectors looks like this: x => x.A + "-" + x.B NHibernate makes "-" an extra parameter. This parameter gets the SQL type nvarchar and so the whole statement gets converted on the SQL Server from varchar to nvarchar . The problem with this is, that SQL Server has a huge problem if the queried column is of type varchar instead of nvarchar . This is because the column is of another type than the parameter and so the index can't be used . I cannot change the type of the column

Byte string spanning more than one line

心不动则不痛 提交于 2019-12-11 11:32:55
问题 I need to parse byte string which spans more than one line in the source code. Like this self.file.write(b'#compdef %s\n\n' '_arguments -s -A "-*" \\\n' % (self.cmdName,)) this line throws the following exception builtins.SyntaxError: cannot mix bytes and nonbytes literals which can be fixed in the following way self.file.write(b'#compdef %s\n\n\'\'_arguments -s -A "-*" \\\n' % (self.cmdName,)) Notice the backslashes after \n . but this fix does the follow the project rules of less than 79

What are the differences in string literals between C#, Visual Basic.NET, and Managed C++?

旧巷老猫 提交于 2019-12-11 03:55:36
问题 I'm referring to the syntax for writing strings in code, including multiline strings and verbatim strings. (Context: I'm working on a tool that scans code, and it's important to determine when tokens are inside a string.) Thanks! 回答1: Here's a quick breakdown between languages Managed C++: Supports string literals much in the way that vanilla C,C++ or C# does. That is strings are designated by " and allow for character escape sequences in the middle via a \. C#: Supports normal string

C++ inserting wchar_t backslash into string

孤街浪徒 提交于 2019-12-11 02:07:24
问题 I have a wide char literal: const wchar_t* charSet = L" !\"#$%&'()*+,-./0123456789:;<=>?\n" L"@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_\n" L"`abcdefghijklmnopqrstuvwxyz{|}~\n"; When I pass it into text processor '\'(backslash) isn't there.Now if I put instead \\ it I am getting compile time error: "missing closing quote" So how do I put backslash into such a char string? 回答1: As for your original code L" !\"#$%&'()*+,-./0123456789:;<=>?\n" you simply missed escaping the quote character " again.

Preprocessor Stringizing Operator with String Literal Prefixes

孤人 提交于 2019-12-10 21:49:45
问题 So I want to do the traditional thing to do with the stringizing operator in a macro: #define FOO(x) foo(#x, (x)) However I need to use a string literal prefix: http://en.cppreference.com/w/cpp/language/string_literal Which is a problem because if I need a UTF-32 string literal I try to do this: #define FOO(x) foo(U#x, (x)) But gcc 4.9.2 complains: error: 'U' was not declared in this scope Is there a way to make the compiler treat the U as a prefix to the stringized macro variable? 回答1: Yes,

Multi-line string literals behave sane only in REPL and Worksheet

旧巷老猫 提交于 2019-12-10 20:59:15
问题 REPL: scala> val a = "hello\nworld" a: String = hello world scala> val b = """hello | world""" b: String = hello world scala> a == b res0: Boolean = true Worksheet: val a = "hello\nworld" //> a : String = hello //| world val b = """hello world""" //> b : String = hello //| world a == b //> res0: Boolean = true Normal Scala code: val a = "hello\nworld" val b = """hello world""" println(a) println(b) println(a == b) Output: hello world hello world false Why does the comparison yield true in the

Use proper string literal in templated function in C++

允我心安 提交于 2019-12-10 20:35:35
问题 I have a function, that is templated to match every std::basic_string instantiation: template <typename _valueType> void addFoo(std::basic_string<_valueType>& string_) { string_ += "foo"; } I want "foo" to be _valueType -dependent literal. I would like not to use specialization, because in the actual project I have whole class templated and it would be a lot of work. I am currently using if constexpr in function body, but problems start, when I have function taking default parameter like this