Unicode 16進数変換ツール(複数行対応)

プログラム

Unicode 16進数変換ツール

Unicode 16進数変換ツール(複数行対応)






<!DOCTYPE html>
<html lang="ja">
<head>
  <meta charset="UTF-8">
  <title>Unicode 16進数変換ツール</title>
  <style>
    textarea {
      width: 100%;
      height: 100px;
    }
    pre {
      background-color: #f0f0f0;
      padding: 10px;
      white-space: pre-wrap;
    }
  </style>
</head>
<body>
  <h2>Unicode 16進数変換ツール(複数行対応)</h2>
  <textarea id="inputText" placeholder="ここに文字を入力してね(複数行OK!)"></textarea><br>
  <button onclick="convertToUnicode()">変換</button>
  <button onclick="copyResult()">コピー</button>
  <pre id="result"></pre>

  <script>
    function convertToUnicode() {
      const input = document.getElementById("inputText").value;
      const hexCodes = Array.from(input).map(char => {
        if (char === '\n') return '\n';
        const codePoint = char.codePointAt(0).toString(16).toUpperCase();
        return "U+" + codePoint.padStart(4, '0');
      });
      document.getElementById("result").textContent = hexCodes.join(" ");
    }

    function copyResult() {
      const resultText = document.getElementById("result").textContent;
      navigator.clipboard.writeText(resultText).then(() => {
        alert("コピーしたよ!📋");
      }).catch(err => {
        alert("コピーに失敗しちゃった…: " + err);
      });
    }
  </script>
</body>
</html>

JavaScript

Posted by eightban