Summary Files Commits Branches @commit @diff @stats
path: root / string.html
blob: b22a1efacd2790673cce5bd8733478b74fbfa4b5 (plain) (blame)
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
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="author" content="Syndamia">
		<meta name="robots" content="index, follow">
		<meta name="viewport" content="width=device-width, initial-scale=1.0">
		<title>String functions</title>
<style>
#notice {
	font-size: 0.9em;
	color: gray;
	font-style: italic;
}
#strlen-l {
	font-weight: bold;
}
</style>
	</head>
	<body>
		<header>
			<h2>String functions</h2>
			<p>
			An asortment of functions for simple (local) string manipulation and inspection.
			</p>
			<a href="/">Home</a>
			<span id="notice">&emsp; Made by <a href="https://syndamia.com">Syndamia</a>, licensed under <a href="https://gitlab.com/Syndamia/small-web-utilities/-/blob/main/LICENSE">GNU GPLv3</a></span>
			<hr>
		</header>

		<div>
			<p>String length: <span id="strlen-l">0</span></p>
			<textarea rows="10" cols="80" id="strlen-ta" placeholder="Input here"></textarea>
		</div>
		<br>

		<div>
			<p>String to HTML entities</p>
			<textarea rows="10" cols="80" id="strtohtmlent-in" placeholder="Input here"></textarea>
			<textarea rows="10" cols="80" id="strtohtmlent-out" placeholder="Output here"></textarea>
		</div>
		<script>
			const strlenLabel = document.getElementById('strlen-l');
			const strlenIn = document.getElementById('strlen-ta');
			function stringLength() {
				strlenLabel.innerText = this.value.length;
			}
			stringLength.call(strlenIn);
			strlenIn.addEventListener('input', stringLength);

			const strtoheIn = document.getElementById('strtohtmlent-in');
			const strtoheOut = document.getElementById('strtohtmlent-out');
			function stringToHTMLEntities() {
				strtoheOut.value = '';
				for (var i = 0; i < this.value.length; i++) {
					strtoheOut.value += '&#' + this.value.charCodeAt(i) + ';';
				}
			}
			stringToHTMLEntities.call(strtoheIn);
			strtoheIn.addEventListener('input', stringToHTMLEntities);
		</script>
	</body>
</html>