[英]How can I select keys from a hash in Ruby with a string of javascript?
[英]How can I get hash from string and then string from hash back in javascript
我有一個很長的字符串(〜70,000個字符),我想插入URL。 我需要在瀏覽器中實現后退,因此當URL更改時,我的應用程序將做出反應並更改其狀態。
這是我用來從字符串生成哈希碼的函數:
String.prototype.hashCode = function () {
var hash = 0, i, char;
if (this.length == 0) return hash;
var l = this.length;
for (i = 0; i < l; i++) {
char = this.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
hash |= 0; // Convert to 32bit integer
}
return hash;
};
但是,如何從哈希中取回我的字符串呢?
編輯:還有其他方法可以壓縮這么長的URL嗎?
你不能 哈希是一種單向函數。 560,000位不能轉換為32位並再次轉換。
與魔術! (說不可能)
根據您的用例,也許您可以使用URL縮短服務來壓縮URL。 看下面的例子: https ://twitter.com/peterjaric/status/336941762838945792(我使用tinyurl壓縮了長數據uri)。
直接鏈接到tinyurl-page: http : //tinyurl.com/peterjaric-page1
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.