Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I display a backslash in a browser using javascript?

as mentioned below, I have some code in my jsp inside a script tag .

I am getting this: 444444444666666666666666666\888888888888

but I want this: 444444444\666666666666666666\\888888888888
(The backslash should be escaped)

So how can i avoid this and display the text as it is? I have tried different ways to replace the backslash("\") but I have been unsuccessful.

 <script>
      var mytxt ="444444444\666666666666666666\\888888888888";
  document.write(mytxt);   
 </script>

  Actual O/P in browser : 444444444666666666666666666\888888888888
  Expected O/P in browser : 444444444\666666666666666666\\888888888888
like image 718
Satya Avatar asked Mar 21 '26 14:03

Satya


1 Answers

Escape each backslash with another backslash:

444444444\\666666666666666666\\\\888888888888

When you want to represent a single \, use \\.

like image 58
Blender Avatar answered Mar 23 '26 04:03

Blender