How can I effectively split a multi-line string containing a backslash leading to unwanted escape characters in separate lines?
Here is an example of the input that I have in mind:
strInput = '''signalArr(0)="ASCB D\axx\bxx\fxx\nxx"
signalArr(1)="root\rxx\txx\vxx"'''
I tried this (to convert a single backslash to a double. So a backslash escape would take precedence, and the following character would be processed "normally"):
def doubleBackslash(inputString):
inputString.replace('\\','\\\\')
inputString.replace('\a','\\a')
inputString.replace('\b','\\b')
inputString.replace('\f','\\f')
inputString.replace('\n','\\n')
inputString.replace('\r','\\r')
inputString.replace('\t','\\t')
inputString.replace('\v','\\v')
return inputString
strInputProcessed = doubleBackslash(strInput)
I would like to receive:
lineList = strInputProcessed.splitlines()
>> ['signalArr(0)="ASCB D\axx\bxx\fxx\nxx"','signalArr(1)="root\rxx\txx\vxx"']
What I got:
>> ['signalArr(0)="ASCB D\x07xx\x08xx', 'xx', 'xx"', 'signalArr(1)="root', 'xx\txx', 'xx"']
source
share