変換ツール( native ⇔ ascii )
変換対象変換結果
サンプルHTML
native2ascii.html<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>JavaScriptでnative2ascii</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$("#n2a").click(function() {
var raw = $("#in").val();
var result = "";
while(true){
if (raw.length == 0) break;
var t = raw.substring(0,1);
raw = raw.substring(1);
var tmp = t.charCodeAt().toString(16);
if (tmp.length >= 4) {
result += "\\u" + tmp;
} else {
result += t;
}
}
$("#out").val(result);
});
$("#a2n").click(function() {
var raw = $("#in").val();
var result = "";
while(true) {
if (raw.length == 0) break;
var index = raw.indexOf("\\u");
if (index == -1) {
result += raw;
break;
}
if (0 < index) {
result += raw.substring(0, index);
}
if (index + 6 <= raw.length) {
var tmp = parseInt(raw.substring(index + 2, index + 6), 16);
result += String.fromCharCode(tmp);
raw = raw.substring(index + 6);
} else {
break;
}
}
$("#out").val(result);
});
});
</script>
</head>
<body>
<h2>JavaScriptでnative2ascii</h2>
変換対象<br/>
<textarea id="in" style="width:800px;height:80px;"></textarea><br/>
<input type="button" id="n2a" value="native2ascii">
<input type="button" id="a2n" value="ascii2native"><br />
変換結果<br/>
<textarea id="out" style="width:800px;height:80px;"></textarea><br/>
</body>
</html>