Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Include )" in raw string literal without terminating said literal

The two characters )" terminate the raw string literal in the example below.
The sequence )" could appear in my text at some point, and I want the string to continue even if this sequence is found within it.

R"(       Some Text)"   )";       // ^^ 

How can I include the sequence )" within the string literal without terminating it?

like image 981
Andreas DM Avatar asked May 18 '15 16:05

Andreas DM


People also ask

What is a raw string literal?

Raw String Literal in C++ A Literal is a constant variable whose value does not change during the lifetime of the program. Whereas, a raw string literal is a string in which the escape characters like ' \n, \t, or \” ' of C++ are not processed. Hence, a raw string literal that starts with R”( and ends in )”.

What is a raw string literal in Python?

Python raw string is created by prefixing a string literal with 'r' or 'R'. Python raw string treats backslash (\) as a literal character. This is useful when we want to have a string that contains backslash and don't want it to be treated as an escape character.

What is an example of a string literal?

A string literal is a sequence of zero or more characters enclosed within single quotation marks. The following are examples of string literals: 'Hello, world!' 'He said, "Take it or leave it."'

What is raw string literal in Golang?

String literals A string literal represents a string constant obtained from concatenating a sequence of characters. There are two forms: raw string literals and interpreted string literals. Raw string literals are character sequences between back quotes, as in `foo` .


1 Answers

Raw string literals let you specify an almost arbitrary* delimiter:

//choose ### as the delimiter so only )###" ends the string R"###(       Some Text)"   )###";   

*The exact rules are: "any member of the basic source character set except: space, the left parenthesis (, the right parenthesis ), the backslash \, and the control characters representing horizontal tab, vertical tab, form feed, and newline" (N3936 §2.14.5 [lex.string] grammar) and "at most 16 characters" (§2.14.5/2)

like image 139
chris Avatar answered Sep 28 '22 05:09

chris