Convert or encode id "1_0xr__abc @ xyz.com__abc @ uvw.com__054gg" to srtring

Is there anything that can convert or encode this id ="1_0xr__abc@xyz.com__abc@uvw.com__054gg"

to a string with a specific number

Example Let's suppose it id="abcd@er.com"

converts to any numeric string"1233452556"

Is it possible to do this in javascript?

+3


source to share


1 answer


you can hash a string

String.prototype.hashCode = function() {
      var hash = 0, i, chr, len;
      if (this.length == 0) return hash;
      for (i = 0, len = this.length; i < len; i++) {
        chr   = this.charCodeAt(i);
        hash  = ((hash << 5) - hash) + chr;
        hash |= 0; // Convert to 32bit integer
      }
      return hash;
    };

      

Source: http://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/



use

id="abcd@er.com".hashCode();

      

+1


source







All Articles