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
-2
votes
2 answers

Convert string to raw string

char str[] = "C:\Windows\system32" auto raw_string = convert_to_raw(str); std::cout << raw_string; Desired output: C:\Windows\system32 Is it possible? I am not a big fan of cluttering my path strings with extra backslash. Nor do I like an…
user3600124
  • 829
  • 1
  • 7
  • 19
-2
votes
2 answers

how do I extract a input string literal containing escape sequences like \a,\16 as a raw string?

I want to extract the following input text as raw string but for both r''+ string, repr(string) \a,\1 are getting replaced with \x07,\x01. Will appreciate some help input_txt = 'ab\a\1' t1=r''+input_txt t2=repr(input_txt) print(t1) print(t2)
-2
votes
1 answer

Make Python string a raw string

I have the following code: #!/usr/bin/python import os from sys import exit as EXIT File = os.path.realpath(__file__) dir = os.path.dirname(File) os.chdir(dir) path_file = os.path.join(dir,"path.txt") filo = open(path_file) lines =…
user324747
  • 255
  • 3
  • 16
-2
votes
1 answer

Substituting backlashes with forward slashes in a string

Edited question: I am writing a python function that takes the string of a path as copy-pasted from windows (so with backslashes) and returns a string with forwardslashes, that can be used by python as a path. The problem arises with the combination…
Pauli
  • 170
  • 3
  • 9
-2
votes
1 answer

How to programmatically convert r'\n' to '\n' in python?

Let's say I have a raw string like r'\n' that corresponds to '\\n'. Is there a way to interpret the raw string as the "normal" string '\n' with the line break meaning?
bluePhlavio
  • 537
  • 5
  • 18
-3
votes
0 answers

Blackslash is converted to double backslashes in python. Im trying to open a file in the code and windows uses backslashes to get to different folders

I'm using this command in my code with open(r"files\data.txt", "r") as file: and I'm getting this error No such file or directory: 'files\\data.txt' I've also tried using \ as I've seen this mentioned as a solution but it still doesn't work with…
Risly
  • 1
-8
votes
2 answers

Create and parse a Python Raw string literal R""

Edit I'm not sure if this question is being read correctly. I already know what string formats are in Python. Every single little detail, I already know. Please stop directing me to questions about string types in Python. This is a specific question…
user557597
-9
votes
1 answer

XOR - Explaining of 3 lines

We are doing a school project where we need to explain code line by line. We need to explain the following 3 lines: // TODO: This is where the magic of XOR is happening. Are you able to explain what is going on? for (int i = 0; i <…
1 2 3
9
10