Skip to content

Instantly share code, notes, and snippets.

@oliverlundquist
Created May 11, 2016 02:19
Show Gist options
  • Save oliverlundquist/f98050e5c503d8a68dbfc6d008946796 to your computer and use it in GitHub Desktop.
Save oliverlundquist/f98050e5c503d8a68dbfc6d008946796 to your computer and use it in GitHub Desktop.
Double Byte to Single Byte (JS)
var input = 'Taro Suzuki 234234234456456';
var output = input
.replace(/[Aa]/g, 'A')
.replace(/[Bb]/g, 'B')
.replace(/[Cc]/g, 'C')
.replace(/[Dd]/g, 'D')
.replace(/[Ee]/g, 'E')
.replace(/[Ff]/g, 'F')
.replace(/[Gg]/g, 'G')
.replace(/[Hh]/g, 'H')
.replace(/[Ii]/g, 'I')
.replace(/[Jj]/g, 'J')
.replace(/[Kk]/g, 'K')
.replace(/[Ll]/g, 'L')
.replace(/[Mm]/g, 'M')
.replace(/[Nn]/g, 'N')
.replace(/[Oo]/g, 'O')
.replace(/[Pp]/g, 'P')
.replace(/[Qq]/g, 'Q')
.replace(/[Rr]/g, 'R')
.replace(/[Ss]/g, 'S')
.replace(/[Tt]/g, 'T')
.replace(/[Uu]/g, 'U')
.replace(/[Vv]/g, 'V')
.replace(/[Ww]/g, 'W')
.replace(/[Xx]/g, 'X')
.replace(/[Yy]/g, 'Y')
.replace(/[Zz]/g, 'Z')
.replace(/[1]/g, '1')
.replace(/[2]/g, '2')
.replace(/[3]/g, '3')
.replace(/[4]/g, '4')
.replace(/[5]/g, '5')
.replace(/[6]/g, '6')
.replace(/[7]/g, '7')
.replace(/[8]/g, '8')
.replace(/[9]/g, '9')
.replace(/[0]/g, '0')
.replace(/[ ]/g, ' ')
.toUpperCase();
// Input: Taro Suzuki 234234234456456
// Output: TARO SUZUKI 234234234456456
console.log('Input: ' + input);
console.log('Output: ' + output);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment