I have some problems regarding escape characters.
Problem I:
I have a string in the form of:
String = "%C3%85"
String is the representation of two bytes in UTF-8 encoding this char: "Å".
Except: "\x" is replaced with "%".
So I want to alter String to look like this:
String = "\xC3\x85"
Problem II:
I have a String in the form:
*String* = "\\x33"
Now I want to convert it into the UTF-8 byte representation of that which should look like:
String = b"\x33"
How do I do that?
Approaches I tried:
I tried using the replace method:
string.replace("%","\") -- wont work since \ escapes "
string.replace("%","\\") -- wont work since this produces problem II
string.replace("%","\x00").replace("00","") -- wont work since "\x00" is a char by its own.
bytes(string.replace("%","\\") ) -- wont work since this basically comes down to problem II
One approach that works but is way more work than seems to be needed is to create a dictionary with all characters in the form of:
"%00" = "\x00"
...
...
But well....this should be automatable since its basically just replacing % with x\
I am out of luck and couldnt find any help anywhere on the internet.
lmgtfy wont help me either;)
Thanks for any help!