-1

I want to print the string containing backslash at the end.

echo "test\";
echo "test\\";

I expect the o/p like.

test\
test\\

But in first case i am getting

Syntax error, unexpected end of file

In second case i am getting below result.

test\ 

Please help me to achieve the expected o/p. Thank you

Deepak Kishore
  • 128
  • 1
  • 9
  • Backslash is a control character, so you need to escape it twice \\ to specify a single literal backslash. This question must be a duplicate of something else. – Tim Biegeleisen Mar 25 '20 at 09:16

1 Answers1

0

\ is the "escaping-character". This means that the special characters (like ";:....) will be interpreted as a usual string.

echo "hello" // -> hello
echo "hello\"" // -> hello"
echo "hello\\" // -> hello\

You can read more here: Escaping Strings in JavaScript

messerbill
  • 5,499
  • 1
  • 27
  • 38