How Do I Convert String To Base36 In Javascript
var sVar = 'someString'; I tried sVar.toString(36) as inferred from num.toString(2). But it doesn't work. I know to convert from base64 you use atob/btoa but I could not find for b
Solution 1:
You can use parseInt
to convert a string to a base-36 integer.
var myString = "somestring";
var myNum = parseInt(myString, 36); /* 2913141654103084 */
And you can use .toString
to convert back to a string.
myNum.toString(36) /* "somestring" */
Both functions take a numeric "radix" (an integer between 2 and 36 specifying the base to use for representing numeric values) as a parameter, which should be 36
for base-36.
Post a Comment for "How Do I Convert String To Base36 In Javascript"