string-literals

StringFormat is ignored

拜拜、爱过 提交于 2019-11-27 23:04:50
问题 This is my binding (shortened, Command-Property is also bound) <MenuItem Header="Key" CommandParameter="{Binding StringFormat='Key: {0}', Path=PlacementTarget.Tag, RelativeSource={RelativeSource AncestorType=ContextMenu}}"/> The Tag-Property of ContectMenu's PlacementTarget is a String like "Short.Plural" What i expect to receive in the Command-Handler is: Key: Short.Plural But what i acutally receive is: Short.Plural 回答1: Label does not use StringFormat but ContentStringFormat. Use it this

Can a string literal be subscripted in a constant expression?

泄露秘密 提交于 2019-11-27 22:50:32
This is valid, because a constexpr expression is allowed to take the value of "a glvalue of literal type that refers to a non-volatile object defined with constexpr, or that refers to a sub-object of such an object" (§5.19/2): constexpr char str[] = "hello, world"; constexpr char e = str[1]; However, it would seem that string literals do not fit this description: constexpr char e = "hello, world"[1]; // error: literal is not constexpr 2.14.5/8 describes the type of string literals: Ordinary string literals and UTF-8 string literals are also referred to as narrow string literals. A narrow

GCC 4.7 Source Character Encoding and Execution Character Encoding For String Literals?

北慕城南 提交于 2019-11-27 20:47:38
Does GCC 4.7 on Linux/x86_64 have a default character encoding by which it validates and decodes the contents of string literals in C source files? Is this configurable? Further, when linking the string data from string literals into the data section of the output does it have a default execution character encoding? Is this configurable? In any configuration is it possible to have a source character encoding that differs from the execution character encoding? (That is will gcc ever transcode between character encodings?) Christian Stieber I don't know how well these options actually work (not

Does javascript have literal strings?

非 Y 不嫁゛ 提交于 2019-11-27 20:21:41
In c# and ruby and many other languages you can denote a string as to not need escaping. in c# its like this string s = @"\whatever\this\is"; the results are when printed \whatever\this\is my question is, is this supported in any form in javascript? Peter Bailey Short answer: No Long answer: Noooooooooooooooooooooooooo Pointy I don't know what you're getting at, but one way to get around the problem of escaping (etc) is use a trick that John Resig seems to like a lot. You include <script> blocks in a page, but give them a "type" like "text/plain" to make sure that the browser doesn't hand them

How do I encode Unicode character codes in a PowerShell string literal?

不打扰是莪最后的温柔 提交于 2019-11-27 19:36:57
How can I encode the Unicode character U+0048 (H), say, in a PowerShell string? In C# I would just do this: "\u0048" , but that doesn't appear to work in PowerShell. Shay Levy Replace '\u' with '0x' and cast it to System.Char: PS > [char]0x0048 H You can also use the "$()" syntax to embed a Unicode character into a string: PS > "Acme$([char]0x2122) Company" AcmeT Company Where T is PowerShell's representation of the character for non-registered trademarks. According to the documentation, PowerShell Core 6.0 adds support with this escape sequence: PS> "`u{0048}" H see https://docs.microsoft.com

Differentiate String Literal from Char Array

三世轮回 提交于 2019-11-27 17:14:05
问题 I want to write some function that takes a string literal - and only a string literal: template <size_t N> void foo(const char (&str)[N]); Unfortunately, that is too expansive and will match any array of char - whether or not it's a true string literal. While it's impossible to tell the difference between these at compile-time - without having to resort to requiring the caller to wrap the literal/array - at run-time, the two arrays will be in entirely different places in memory: foo("Hello");

Possible to make custom string literal prefixes in Python?

徘徊边缘 提交于 2019-11-27 16:43:10
问题 Let's say I have a custom class derived from str that implements/overrides some methods: class mystr(str): # just an example for a custom method: def something(self): return "anything" Now currently I have to manually create instances of mystr by passing it a string in the constructor: ms1 = mystr("my string") s = "another string" ms2 = mystr(s) This is not too bad, but it lead to the idea that it would be cool to use a custom string prefix similar to b'bytes string' or r'raw string' or u

Why is passing a string literal into a char* argument only sometimes a compiler error?

元气小坏坏 提交于 2019-11-27 15:38:51
I'm working in a C, and C++ program. We used to be compiling without the make-strings-writable option. But that was getting a bunch of warnings, so I turned it off. Then I got a whole bunch of errors of the form "Cannot convert const char* to char* in argmuent 3 of function foo". So, I went through and made a whole lot of changes to fix those. However, today, the program CRASHED because the literal "" was getting passed into a function that was expecting a char*, and was setting the 0th character to 0. It wasn't doing anything bad, just trying to edit a constant, and crashing. My question is,

String in function parameter

若如初见. 提交于 2019-11-27 15:04:40
问题 int main() { char *x = "HelloWorld"; char y[] = "HelloWorld"; x[0] = 'Z'; //y[0] = 'M'; return 0; } In the above program, HelloWorld will be in read-only section(i.e string table). x will be pointing to that read-only section, so trying to modify that values will be undefined behavior. But y will be allocated in stack and HelloWorld will be copied to that memory. so modifying y will works fine. String literals: pointer vs. char array Here is my Question: In the following program, both char

C++ Comparison of String Literals

巧了我就是萌 提交于 2019-11-27 13:24:38
I'm a c++ newbie (just oldschool c). My son asked for help with this and I'm unable to explain it. If he had asked me "how do I compare strings" I would have told him to use strcmp(), but that isn't what is confusing me. Here is what he asked: int main() { cout << ("A"< "Z"); } will print 1 int main() { cout << ("Z"< "A"); } will also print 1, but int main() { cout << ("Z"< "A"); cout << ("A"< "Z"); } will then print 10. Individually both cout statements print 1, but executed in a row I get a different answer? You are comparing memory addresses. Apparently your compiler places the string