Reputation: 51
I am new to Javascript
coding. The current task I am working on is creating HTML Documents from a text document.In a particular case, I have a complex string (alphanumeric string with backslashes). I need the HTML to print it the way the text is present.
However, the HTML created escapes all backslashes.
Input Text:
3583859858.8200040004xxxx\00\0200040004\t0\t194.3\t39874\t7975\t90\t62\t0.1\t194.3\t200\t35.00\t35.00\t35.00\t194\t2.1\t12541\t12650\t13468\t13421\t13481\t13932\t35.00\t35.00\n
Output in HTML:
3583859858.8200040004xxxx0040004 0t194.3 39874 7975 90 62 0.1 194.3 200 35.00 35.00 35.00t194 2.1 12541 12650 13468 13421 13481 13932 35.00 35.00
I tried below solutions to other relevant questions but it did not work
How to escape backslash in JavaScript?
Backslashes - Regular Expression - Javascript
How can I replace a backslash with a double backslash using RegExp?
Request help from seniors here
Upvotes: 0
Views: 1646
Reputation: 1044
One Solution is to use JAVASCRIPT / JQUERY
Checkout This Demo
var string = '3583859858.8200040004xxxx\00\0200040004\t0\t194.3\t39874\t7975\t90\t62\t0.1\t194.3\t200\t35.00\t35.00\t35.00\t194\t2.1\t12541\t12650\t13468\t13421\t13481\t13932\t35.00\t35.00\n';
$("#result").html(string);
// IF THIS IS NOT WORKING THEN TRY THIS
var htmlString = string.split("\\");
$("#resultHtml").html(htmlString);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="result"></div>
<br>
<div id="resultHtml"></div>
<!-- Third Solution **   FOR \t AND FOR \n-->
<div>3583859858.8200040004xxxx\00\0200040004 0 194.3 39874 7975 90 62 0.1 194.3 200 35.00 35.00 35.00 194 2.1 12541 12650 13468 13421 13481 13932 35.00 35.00 </div>
This Might Be Helpful.
Upvotes: 1
Reputation: 8786
Use html character instead. Replace all backslashes with
\
Example
<span>\t0\t194.3\t39874</span>
Upvotes: 0