Convert String to Hankaku Case - Node.js String

Node.js examples for String:Case

Description

Convert String to Hankaku Case

Demo Code


String.prototype.toHankakuCase = function()
{
  var c, i = this.length, a = [];

  while(i--)/*w  w w .  j  a  v  a2s .c  o  m*/
  {
    c = a[i] = this.charCodeAt(i);

    switch(true)
    {
      case (0xFF01 <= c && c <= 0xFF5E):
        a[i] -= 0xFEE0;
        break;
      case (c == 0x3000):
        a[i] = 0x0020;
        break;
    };
  };


  return String.fromCharCode.apply(null, a);
};

Related Tutorials