• <legend id='DWx32'><style id='DWx32'><dir id='DWx32'><q id='DWx32'></q></dir></style></legend>

      <bdo id='DWx32'></bdo><ul id='DWx32'></ul>
    <i id='DWx32'><tr id='DWx32'><dt id='DWx32'><q id='DWx32'><span id='DWx32'><b id='DWx32'><form id='DWx32'><ins id='DWx32'></ins><ul id='DWx32'></ul><sub id='DWx32'></sub></form><legend id='DWx32'></legend><bdo id='DWx32'><pre id='DWx32'><center id='DWx32'></center></pre></bdo></b><th id='DWx32'></th></span></q></dt></tr></i><div id='DWx32'><tfoot id='DWx32'></tfoot><dl id='DWx32'><fieldset id='DWx32'></fieldset></dl></div>

    <small id='DWx32'></small><noframes id='DWx32'>

      <tfoot id='DWx32'></tfoot>

        Javascript 将字符串格式的 GUID 转换为 Base64

        时间:2023-10-01

            <tbody id='KAYBF'></tbody>

            <bdo id='KAYBF'></bdo><ul id='KAYBF'></ul>
            <i id='KAYBF'><tr id='KAYBF'><dt id='KAYBF'><q id='KAYBF'><span id='KAYBF'><b id='KAYBF'><form id='KAYBF'><ins id='KAYBF'></ins><ul id='KAYBF'></ul><sub id='KAYBF'></sub></form><legend id='KAYBF'></legend><bdo id='KAYBF'><pre id='KAYBF'><center id='KAYBF'></center></pre></bdo></b><th id='KAYBF'></th></span></q></dt></tr></i><div id='KAYBF'><tfoot id='KAYBF'></tfoot><dl id='KAYBF'><fieldset id='KAYBF'></fieldset></dl></div>

            <small id='KAYBF'></small><noframes id='KAYBF'>

            <tfoot id='KAYBF'></tfoot>
              <legend id='KAYBF'><style id='KAYBF'><dir id='KAYBF'><q id='KAYBF'></q></dir></style></legend>

                1. 本文介绍了Javascript 将字符串格式的 GUID 转换为 Base64的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我在客户端,javascript 上下文中.我有一个字符串格式的 GUID e8b75aff-3422-4529-8a6a-15b33e674f48 我需要它在 Base64 字符串 /1q36CI0KUWKahWzPmdPSA== 如何转换?

                  I'm in a client-side, javascript context. I have a GUID in string format e8b75aff-3422-4529-8a6a-15b33e674f48 and I need it in aBase64 string /1q36CI0KUWKahWzPmdPSA== How do I convert it?

                  谢谢.

                  推荐答案

                  // Convert GUID string to Base-64 in Javascript
                  // by Mark Seecof, 2012-03-31
                  
                  var hexlist = '0123456789abcdef';
                  var b64list = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
                  
                  // GUID string with four dashes is always MSB first,
                  // but base-64 GUID's vary by target-system endian-ness.
                  // Little-endian systems are far more common.  Set le==true
                  // when target system is little-endian (e.g., x86 machine).
                  //
                  function guid_to_base64(g, le) {
                      var s = g.replace(/[^0-9a-f]/ig, '').toLowerCase();
                      if (s.length != 32) return '';
                  
                      if (le) s = s.slice(6, 8) + s.slice(4, 6) + s.slice(2, 4) + s.slice(0, 2) +
                        s.slice(10, 12) + s.slice(8, 10) +
                        s.slice(14, 16) + s.slice(12, 14) +
                        s.slice(16);
                      s += '0';
                  
                      var a, p, q;
                      var r = '';
                      var i = 0;
                      while (i < 33) {
                        a = (hexlist.indexOf(s.charAt(i++)) << 8) |
                          (hexlist.indexOf(s.charAt(i++)) << 4) |
                          (hexlist.indexOf(s.charAt(i++)));
                  
                        p = a >> 6;
                        q = a & 63;
                  
                        r += b64list.charAt(p) + b64list.charAt(q);
                      }
                      r += '==';
                  
                      return r;
                    } // guid_to_base64()
                  
                  //EDIT
                  function tryConversion() {
                    document.getElementById("result").innerText = guid_to_base64(
                      document.getElementById("input_guid").value,
                      document.getElementById("cb_le").checked
                    );
                  }

                  input[type=text] {
                    font-family: monospace;
                    font-size: 12px;
                    width: 270px;
                  }

                  <div><label for="input_guid">GUID</label> <input type="text" maxlength="36" id="input_guid" value="83D95782-BDE4-466F-A490-46820D2B2CDC" />
                  </div>
                  <div><label for="cb_le">Little-Endian?</label> <input type="checkbox" id="cb_le" checked="checked" /></div>
                  <hr />
                  <div><button onclick="javascript:tryConversion()">Convert</button></div>
                  <div>Result: <span id="result"></span></div>

                  这篇关于Javascript 将字符串格式的 GUID 转换为 Base64的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:在 JavaScript 中解码 URL Safe Base64(浏览器端) 下一篇:JavaScript 中的 UTF-16 到 UTF-8 转换

                  相关文章

                    <legend id='yC8pD'><style id='yC8pD'><dir id='yC8pD'><q id='yC8pD'></q></dir></style></legend>
                  1. <small id='yC8pD'></small><noframes id='yC8pD'>

                    <i id='yC8pD'><tr id='yC8pD'><dt id='yC8pD'><q id='yC8pD'><span id='yC8pD'><b id='yC8pD'><form id='yC8pD'><ins id='yC8pD'></ins><ul id='yC8pD'></ul><sub id='yC8pD'></sub></form><legend id='yC8pD'></legend><bdo id='yC8pD'><pre id='yC8pD'><center id='yC8pD'></center></pre></bdo></b><th id='yC8pD'></th></span></q></dt></tr></i><div id='yC8pD'><tfoot id='yC8pD'></tfoot><dl id='yC8pD'><fieldset id='yC8pD'></fieldset></dl></div>

                    <tfoot id='yC8pD'></tfoot>
                      <bdo id='yC8pD'></bdo><ul id='yC8pD'></ul>