Questions tagged [rawstring]

A string literal which would be processed without any language-specific interpretation, avoiding the need of escaping characters and thus providing more legible strings.

Raw strings are particularly useful when a common character needs to be escaped, notably in regular expressions (nested as string literals), where backslash \ is widely used, and in DOS/Windows paths, where backslash is used as a path separator.

143 questions
32
votes
2 answers

How to convert a "raw" string into a normal string?

In Python, I have a string like this: '\\x89\\n' How can I decode it into a normal string like: '\x89\n'
Vince.Wu
  • 870
  • 1
  • 10
  • 17
21
votes
2 answers

escape R"()" in a raw string in C++

string raw_str = R"(R"(foo)")"; If I have R"()" inside a raw string, and that causes the parser to confuse. (ie., it thought the left most )" was the end of the raw string. How do I escape this?
One Two Three
  • 22,327
  • 24
  • 73
  • 114
16
votes
3 answers

Does clojure have raw string?

In Python, I can prefix an r to a string literal (raw string) to tell the interpreter not translate special characters in the string: >>> r"abc\nsdf#$%\^" r"abc\nsdf#$%\^" Is there a way to do the same thing in Clojure?
John Wang
  • 4,562
  • 9
  • 37
  • 54
15
votes
3 answers

Python Regex escape operator \ in substitutions & raw strings

I don't understand the logic in the functioning of the scape operator \ in python regex together with r' of raw strings. Some help is appreciated. code: import re text=' esto .es 10 . er - 12 .23 with [ and.Other ] here is more ;…
JFerro
  • 3,203
  • 7
  • 35
  • 88
14
votes
2 answers

Python raw literal string

str = r'c:\path\to\folder\' # my comment IDE: Eclipse Python2.6 When the last character in the string is a backslash, it seems like it will escape the last single quote and treat my comment as part of the string. But the raw string is supposed…
Stan
  • 37,207
  • 50
  • 124
  • 185
14
votes
2 answers

Why must the delimiters of raw string literals be under 16 chars?

The following program does not compile: #include int main() { std::cout << R"RAW_STRING_LITERAL( hello world )RAW_STRING_LITERAL"; } error: raw string delimiter longer than 16 characters. Why is there a…
Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
14
votes
3 answers

How to create raw string from string variable in python?

You create raw string from a string this way: test_file=open(r'c:\Python27\test.txt','r') How do you create a raw variable from a string variable, such as path = 'c:\Python27\test.txt' test_file=open(rpath,'r') Because I have a file…
alwbtc
  • 28,057
  • 62
  • 134
  • 188
12
votes
1 answer

How do I get the raw representation of a string in Python?

I am making a class that relies heavily on regular expressions. Let's say my class looks like this: class Example: def __init__(self, regex): self.regex = regex def __repr__(self): return…
Tyler Crompton
  • 12,284
  • 14
  • 65
  • 94
11
votes
2 answers

How to correctly write a raw multiline string in Python?

I know that you can create a multi-line string a few ways: Triple Quotes ''' This is a multi-line string. ''' Concatenating ('this is ' 'a string') Escaping 'This is'\ 'a string' I also know that prefixing the string with r will make it a raw…
Josh D
  • 794
  • 4
  • 14
  • 31
11
votes
4 answers

Why can't I end a raw string with a backslash?

I am confused here, even though raw strings convert every \ to \\ but when this \ appears in the end it raises error. >>> r'so\m\e \te\xt' 'so\\m\\e \\te\\xt' >>> r'so\m\e \te\xt\' SyntaxError: EOL while scanning string literal Update: This is now…
Ashwini Chaudhary
  • 244,495
  • 58
  • 464
  • 504
10
votes
3 answers

Python Argparse: Raw string input

Apologies if this has been asked before, I did search for it but all hits seemed to be about python raw strings in general rather than regarding argparse. Anyways, I have a code where the user feeds in a string and then this string is processed.…
Steve
  • 105
  • 1
  • 1
  • 12
9
votes
2 answers

Raw string field value in JSON file

In my JSON file, one of the fields has to carry the content of another file (a string). The string has CRLFs, single/double quotes, tabs. Is there a way to consider my whole string as a raw string so I don't have to escape special characters? Is…
hamza keurti
  • 385
  • 1
  • 2
  • 15
9
votes
1 answer

Python raw string "r" flag equivalent in C#

I am trying to give the file path in C# which contains special/escape characters. I am new to C#. please help me in defining the file path as raw string literals. Following is path (\t has spl meaning): IE_DRIVER_PATH =…
Naveen Kumar R B
  • 6,248
  • 5
  • 32
  • 65
9
votes
2 answers

How to 'raw text' a variable in Python?

I am opening a workbook in openpyxl thus: wb = load_workbook(r'seven.xlsx', data_only=True) The name of the spreadsheet won't always be know in advance, so I need to rewrite this hardcoding to allow for a variable, while still maintaining…
Pyderman
  • 14,809
  • 13
  • 61
  • 106
9
votes
2 answers

Carriage return + newline in raw string literals?

Consider a C++ file that has UNIX line endings (i.e. '\x0a' instead of "\x0d\x0a") and includes following raw string literal: const char foo[] = R"(hello^M )"; (where ^M is the actual byte 0x0d (i.e. carriage return)). What should be the result of…
maxschlepzig
  • 35,645
  • 14
  • 145
  • 182
1
2
3
9 10