首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将id "1_0xr__abc@xyz.com__abc@uvw.com__054gg“转换或编码为数字字符串

将id "1_0xr__abc@xyz.com__abc@uvw.com__054gg“转换或编码为数字字符串
EN

Stack Overflow用户
提问于 2015-06-11 13:24:40
回答 1查看 54关注 0票数 3

有没有什么方法可以将这个id ="1_0xr__abc@xyz.com__abc@uvw.com__054gg"转换或编码成特定的数字字符串

例如,假设要转换为任意数字字符串"1233452556"id="abcd@er.com"

在javascript中可以做到这一点吗?

EN

回答 1

Stack Overflow用户

发布于 2015-06-11 13:29:02

您可以对字符串进行哈希处理

代码语言:javascript
复制
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;
    };

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

要使用

代码语言:javascript
复制
id="abcd@er.com".hashCode();
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30772224

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档