string-literals

C# - How can I convert an escaped string into a literal string? [duplicate]

我怕爱的太早我们不能终老 提交于 2019-12-10 17:31:09
问题 This question already has answers here : Closed 8 years ago . Possible Duplicate: Can I expand a string that contains C# literal expressions at runtime How can I convert an escaped string read from a file at runtime, e.g. "Line1\nLine2" into its literal value: Line1 Line2 Amazingly I have found an example to do the opposite here using CSharpCodeProvider(), which seems like it would be the more difficult conversion. In order to do the opposite it appears I need to generate code to define a

How to separate paragraphs in a string

时光总嘲笑我的痴心妄想 提交于 2019-12-10 16:45:37
问题 Hi guys I really need your help. I was trying to take a multi-line string which was concluded of a few paragraphs and split it into a few individual texts. I realized that whenever I skip a line there is a sequence of \n\r in there. Afterwards I thought that each new line starts with a \n and end with a \r. Therefor, I wrote the following code. using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Text.RegularExpressions; namespace

Does Objective-C use string pooling?

ε祈祈猫儿з 提交于 2019-12-10 15:42:28
问题 I know that Java and C# both use a string pool to save memory when dealing with string literals. Does Objective-C use any such mechanism? If not, why not? 回答1: Yes, string literals like @"Hello world" are never released and they point to the same memory which means that pointer comparison is true. NSString *str1 = @"Hello world"; NSString *str2 = @"Hello world"; if (str1 == str2) // Is true. It also means that a weak string pointer won't change to nil (which happens for normal objects) since

Markdown within yaml / yaml multi-line escape sequence?

半腔热情 提交于 2019-12-10 13:25:37
问题 Is it possible to store unescaped markdown documents in yaml? I've tested key:|+ markdown text block that could have any combination of line breaks, >, -, :, ', " etc etc. This does not work. I need something like CDATA or python style triple-quotes for yamal. Any ideas? 回答1: In literal style of scalar type (what you used in example) line brakes needs still to be "escaped" (in this case intended correctly). And you can only have printable characters. I am not fammiliar with markdown, but in

String literals without having to escape special characters?

大城市里の小女人 提交于 2019-12-10 13:16:51
问题 Is there a string literal form in Objective-c that does not require escaping special characters? In other words, I'm looking for an equivalent to the Python triple quote. I'm trying to put some HTML into an NSString , and would like to avoid having to escape the quotes from all the HTML attributes. 回答1: There's no equivalent to the triple-quote; string literals must always use escapes for special characters. Perhaps the best thing to do would be to put your HTML into a file separate from your

Type of strings

*爱你&永不变心* 提交于 2019-12-10 12:37:45
问题 I got quite confused about what is what. Would you please tell me what each variables type is? char foo[] = "bar"; char *bar = nullptr; char const *qux = nullptr; Aditionally, what is the type of "bar" ? 回答1: The type of foo is char[4] , i.e. a character array containing 4 char s (including the trailing null character '\0' .) String literals can be used to initialize character arrays. If an array is initialized like char str[] = "foo"; , str will contain a copy of the string "foo" . The type

Default advice for using C-style string literals vs. constructing unnamed std::string objects?

北慕城南 提交于 2019-12-10 12:35:35
问题 So C++ 14 introduced a number of user-defined literals to use, one of which is the "s" literal suffix, for creating std::string objects. According to the documentation, its behavior is exactly the same as constructing an std::string object, like so: auto str = "Hello World!"s; // RHS is equivalent to: std::string{ "Hello World!" } Of course constructing an unnamed std::string object could be done prior to C++ 14, but because the C++ 14 way is so much simpler, I think way more people will

How safe and reliable are C++ String Literals?

╄→尐↘猪︶ㄣ 提交于 2019-12-09 10:55:15
问题 So, I'm wanting to get a better grasp on how string literals in C++ work. I'm mostly concerned with situations where you're assigning the address of a string literal to a pointer, and passing it around. For example: char* advice = "Don't stick your hands in the toaster."; Now lets say I just pass this string around by copying pointers for the duration of the program. Sure, it's probably not a good idea, but I'm curious what would actually be going on behind the scenes. For another example,

Check whether equal string literals are stored at the same address

丶灬走出姿态 提交于 2019-12-08 16:14:22
问题 I am developing a (C++) library that uses unordered containers. These require a hasher (usually a specialization of the template structure std::hash) for the types of the elements they store. In my case, those elements are classes that encapsulate string literals, similar to conststr of the example at the bottom of this page. The STL offers an specialization for constant char pointers, which, however, only computes pointers, as explained here, in the 'Notes' section: There is no

How to declare constexpr C string?

烂漫一生 提交于 2019-12-08 15:54:07
问题 I think i quite understand how to use the keyword constexpr for simple variable types, but i'm confused when it comes to pointers to values. I would like to declare a constexpr C string literal, which will behave like #define my_str "hello" That means the compiler inserts the C string literal into every place where i enter this symbol, and i will be able to get its length at compile-time with sizeof. Is it constexpr char * const my_str = "hello"; or const char * constexpr my_str = "hello"; or