Questions tagged [backslash]

The backslash character \ (not to be confused with slash /) is used in many languages as an escape character to modify the meaning of the following character. It is also the directory separator in file paths under DOS and Windows.

The backslash character \ is a mirror version of the slash character /, created for use in computing. Its meaning depends on the context.

  • In many languages, \ followed by a character that has a special meaning makes the next character lose its special meaning. This is especially true inside string literals and regular expressions : for example, in many languages, "a\\b\"" represents the 4-character string a\b".
  • Sometimes \ gives the next character a special meaning. This is mostly the case when \ is followed by a letter or digit in a string literal, where it can be used to specify a control character or other special character. For example, \n specifies a newline in many languages, and \123 often specifies the character whose octal value is 123 (but note that some languages have different rules).
  • In DOS and Windows , the \ character is the directory (folder) separator in file paths. For example, c:\windows\cmd.exe is the file called cmd.exe in the directory called windows at the root of the c: drive.
  • In (La)TeX , \ starts a command name.
  • In Haskell , \ introduces a lambda expression .
991 questions
14
votes
2 answers

Path with backslashes to path with forward slashes javascript

I'm trying to make a local xml file parsing "application" for some colleagues and i'm using the current function to retrieve the files: function ShowFolderFileList(folderspec) { var fso, f, f1, fc, s; fso = new…
Radjiv
  • 141
  • 1
  • 1
  • 4
13
votes
2 answers

Exactly how do backslashes work within backticks?

From the Bash FAQ: Backslashes (\) inside backticks are handled in a non-obvious manner: $ echo "`echo \\a`" "$(echo \\a)" a \a $ echo "`echo \\\\a`" "$(echo \\\\a)" \a \\a But the FAQ does not break down the parsing rules that lead to this…
Jonah
  • 15,806
  • 22
  • 87
  • 161
13
votes
3 answers

Is line continuation with backslash dangerous in Python?

I understand that current best practice for line continuation is to use implied continuation inside parenthesis. For example: a = (1 + 2 + 3 + 4) From PEP8 (https://www.python.org/dev/peps/pep-0008/): The preferred way of wrapping long lines…
gregrf
  • 211
  • 3
  • 8
13
votes
4 answers

ignoring backslash character in python

If I have: a = "fwd" b = "\fwd" how can I ignore the "\" so something like print(a in b) can evaluate to True?
Kevin R.
  • 572
  • 2
  • 5
  • 15
12
votes
6 answers

Concatenate backslash on python

I'm new to python so forgive me if this sounds simple. I want to join a few variables to produce a path. Like this: AAAABBBBCCCC\2\2014_04\2014_04_01.csv Id + '\' + TypeOfMachine + '\' + year + '_' + month + '\' + year + '_' + month + '_' + day +…
Vini.g.fer
  • 11,639
  • 16
  • 61
  • 90
12
votes
6 answers

mysql: replace \ (backslash) in strings

I am having the following problem: I have a table T which has a column Name with names. The names have the following structure: A\\B\C You can create on yourself like this: create table T ( Name varchar(10)); insert into T values…
user1316758
  • 391
  • 1
  • 6
  • 8
11
votes
6 answers

Include header path change from Windows to Linux

I'm porting an application written in C++ from Windows to Linux. I have a problem with the header files path. Windows uses \ and Linux uses /. I am finding it cumbersome to change this in each and every source and header file. Is there some work…
user59988
11
votes
6 answers

Swift - remove single backslash

this is maybe stupid question but I'm new to swift and i actually can't figure this out. I have API which returns url as string "http:\/\/xxx". I don't know how to store URL returned from API in this format. I can't store it to variable because of…
marysmech
  • 183
  • 1
  • 3
  • 10
11
votes
1 answer

escaping backslash in java string literal

I am using Java for a while and come up with this problem: I use hard-coded paths in windows like "D:\Java-code\JavaProjects\workspace\eypros\src" The problem is that I need to escape the backslash character in order to use it with string. So I…
Eypros
  • 5,370
  • 6
  • 42
  • 75
10
votes
4 answers

How to escape the backslashes and the automatically generated escape character in file path in java

I have very small and simple problem but I am not getting solutions on it. Actually I am getting a CSV file path using file chooser. I am entering the data in this csv file in to database using load data local infile query. Suppose my entered file…
Param-Ganak
  • 5,787
  • 17
  • 50
  • 62
10
votes
4 answers

How do I remove double back slash (`\\`) from a bytes object?

For example: t = str.encode(msg) print(t) I am getting double slashes, like this: b'\\xda\\xad\\x94\\xb4\\x0bg\\x92]R\\x9a1y\\x9d\\xed\\x04\\xd5\\x8e+\\x07\\xf8\\x03\\x1bm\\xd6\\x96\\x10\\xca80\\xe26\\x8a But, I would like to get the result…
Swapnil
  • 129
  • 1
  • 5
10
votes
2 answers

Check if string contains slash or backslash in Bash?

I'm currently trying to get my bash script checking if a string containts a "/" or a "\" but somehow I can't get it working. Here is what I got so far: if [[ "$1" == *\/* ]]; then ... elif if [[ "$1" == *\\* ]]; then ... fi Help is much…
user1685565
  • 299
  • 1
  • 5
  • 15
10
votes
4 answers

Find backslash (\) in a string --Python

How can I compare if a backslash is in my string? I don't know how to write the backslash symbol to compare it. I try this but don't work: Code: s = r"\"" print s Output: \" If I try s = "\"" it gives " as output I don't know how to acheive…
Ignacio Gómez
  • 1,587
  • 4
  • 23
  • 41
9
votes
1 answer

How many backslashes are required to escape regexps in emacs' "Customize" mode?

I'm trying to use emacs' customize-group packages to tweak some parts of my setup, and I'm stymied. I see things like this in my .emacs file after I make changes with customize: '(tramp-backup-directory-alist (quote (("\\\\`.*\\\\'" .…
Brighid McDonnell
  • 4,293
  • 4
  • 36
  • 61
9
votes
4 answers

Passing meta-characters to Python as arguments from command line

I'm making a Python program that will parse the fields in some input lines. I'd like to let the user enter the field separator as an option from the command line. I'm using optparse to do this. I'm running into the problem that entering something…
Darlingtonia
  • 238
  • 2
  • 7