Question

How can I convert a month and year value into Unicode using Javascript? For instance, "6, 2013" would become "\u1046, \u1042\u1040\u1041\u1043" (Myanmar text).

Patrick pointed me to Codepen where I got this:

 <script type="text/javascript">
  var d = new Date();
  var mn = (d.getMonth()+1);
  var dn = d.getDate();
  var yn = d.getFullYear();

  var toMyanmar = function (string) {
    var unicodeString = '';
    for (var i=0; i < string.length; i++) {
      var char = string[i];
      if (parseInt(char),16) {
        char = String.fromCharCode(string.charCodeAt(i) + 4112)
      }
      unicodeString += char;
    }
    return unicodeString;
  }

  document.write("<br/>Myanmar Date: ");
  document.write(toMyanmar(''+ mn) + ', ');
  document.write(toMyanmar(''+ dn) + ', ');
  document.write(toMyanmar(''+ yn));
  document.write("<br/>Date; Latin/Arabic numerals: " + mn + ', ' + dn + ', ' + yn);
</script>

<body style="font-family:'Myanmar Text',Arial;"></body>

Zero (0; u1040, #4160) was ignored by this script until I moved the radix number to the same line as "parseInt". (mmrtext.ttf or similar Unicode font is needed to see characters displayed.) So, this now works well for my purpose. And I think will be be the basis for future transcoding of character pages since Myanmar-related languages use many different sets. Thanks a million until you are better paid. R. Holland

Was it helpful?

Solution

Check out http://buildingonmud.blogspot.com/2009/06/convert-string-to-unicode-in-javascript.html

You will have to add some checking if you only want to encode numbers (run each element through parseInt most likely), since it would encode the command and the spaces as well.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top