-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathString Escape Tool.html
More file actions
50 lines (48 loc) · 1.56 KB
/
String Escape Tool.html
File metadata and controls
50 lines (48 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>String Escape Tool</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
textarea {
width: 100%;
height: 200px;
}
button {
margin-top: 10px;
padding: 10px 20px;
}
pre {
background-color: #f4f4f4;
padding: 10px;
border: 1px solid #ccc;
white-space: pre-wrap; /* Preserve whitespace */
}
</style>
</head>
<body>
<h1>String Escape Tool</h1>
<textarea id="inputString" placeholder="Enter your multi-line string or code here..."></textarea>
<button onclick="escapeString()">Escape String</button>
<h2>Escaped Output:</h2>
<pre id="outputString"></pre>
<script>
function escapeString() {
const input = document.getElementById('inputString').value;
const escapedString = input
.replace(/\\/g, '\\\\') // Escape backslashes
.replace(/'/g, "\\'") // Escape single quotes
.replace(/"/g, '\\"') // Escape double quotes
.replace(/\n/g, '\\n') // Escape new lines
.replace(/\r/g, '\\r') // Escape carriage returns
.replace(/\t/g, '\\t'); // Escape tabs
document.getElementById('outputString').textContent = escapedString;
}
</script>
</body>
</html>