14
Japhy
7y

Me: *spends three days trying to format a string to replace two backslashes with one*

Python: Here you go!

str = bytes(str,"utf-8")
.decode("unicode_escape")

Comments
  • 6
    Really, 3 days?
  • 3
    You gonna have a bad time if you use str for a variable name.
  • 0
    @DeepSpace just used it for the example lol
  • 1
    @zacg It’s surprisingly difficult even with regex. But yes, three days but only working for about 3 hours each day.
  • 2
    @Japhy nine hours.

    str.gsub! /\\\\/, '\\'
  • 1
    Hmm not the best way but off the top of my head I would've converted to character array iterated through it and check for the current and next character being a backslash and then only add it once to the new built up string
  • 3
    Being the java guy,

    str.replaceAll("\\\\", "\\");
Add Comment