How can I put an actual backslash in a string literal (not use it for an escape sequence)?

To answer your question directly, put r in front of the string. final= path + r’\xulrunner.exe ‘ + path + r’\application.ini’ But a better solution would be os.path.join: final = os.path.join(path, ‘xulrunner.exe’) + ‘ ‘ + \ os.path.join(path, ‘application.ini’) (the backslash there is escaping a newline, but you could put the whole thing on one … Read more

How can I print a single backslash?

You need to escape your backslash by preceding it with, yes, another backslash: print(“\\”) And for versions prior to Python 3: print “\\” The \ character is called an escape character, which interprets the character following it differently. For example, n by itself is simply a letter, but when you precede it with a backslash, … Read more

How to replace ” \ ” with ” \\ ” in java

Don’t use String.replaceAll in this case – that’s specified in terms of regular expressions, which means you’d need even more escaping. This should be fine: String escaped = original.replace(“\\”, “\\\\”); Note that the backslashes are doubled due to being in Java string literals – so the actual strings involved here are “single backslash” and “double … Read more

Backslashes in single quoted strings vs. double quoted strings

Double-quoted strings support the full range of escape sequences, as shown below: \a Bell/alert (0x07) \b Backspace (0x08) \e Escape (0x1b) \f Formford (0x0c) \n Newline (0x0a) \r Return (0x0d) \s Space (0x20) \t Tab (0x09) \v Vertical tab (0x0b) For single-quoted strings, two consecutive backslashes are replaced by a single backslash, and a backslash … Read more

Weird backslash substitution in Ruby

Quick Answer If you want to sidestep all this confusion, use the much less confusing block syntax. Here is an example that replaces each backslash with 2 backslashes: “some\\path”.gsub(‘\\’) { ‘\\\\’ } Gruesome Details The problem is that when using sub (and gsub), without a block, ruby interprets special character sequences in the replacement parameter. … Read more