有没有什么方法可以将这个id ="1_0xr__abc@xyz.com__abc@uvw.com__054gg"转换或编码成特定的数字字符串
例如,假设要转换为任意数字字符串"1233452556"的id="abcd@er.com"
在javascript中可以做到这一点吗?
发布于 2015-06-11 13:29:02
您可以对字符串进行哈希处理
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/
要使用
id="abcd@er.com".hashCode();https://stackoverflow.com/questions/30772224
复制相似问题