最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

String to Unique hash in JavascriptJquery - Stack Overflow

programmeradmin0浏览0评论

Is there a function in Javascript / Jquery which will make hashtag from a string ? I'm looking for the answer for few minutes and i can't find it :/ Maybe there is some other way to make it ? I have Symfony 2.4 application.

I have my form data serialized to string, for example:

"cloud_adm_dictionary_type%5Bitems%5D%5B0%5D%5BdictName%5D=Otwartabbb&cloud_adm_dictionary_type%5Bitems%5D%5B0%5D%5BdictValue1%5D=fa-comments-o+text-muted&cloud_adm_dictionary_type%5Bitems%5D%5B0%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B1%5D%5BdictName%5D=Wycena&cloud_adm_dictionary_type%5Bitems%5D%5B1%5D%5BdictValue1%5D=fa-comments-o+text-muted&cloud_adm_dictionary_type%5Bitems%5D%5B1%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B2%5D%5BdictName%5D=Negocjacje&cloud_adm_dictionary_type%5Bitems%5D%5B2%5D%5BdictValue1%5D=fa-comments-o+text-muted&cloud_adm_dictionary_type%5Bitems%5D%5B2%5D%5BisDefault%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B2%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B3%5D%5BdictName%5D=Wygrana&cloud_adm_dictionary_type%5Bitems%5D%5B3%5D%5BdictValue1%5D=fa-thumbs-o-up+text-primary&cloud_adm_dictionary_type%5Bitems%5D%5B3%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B4%5D%5BdictName%5D=Przegrana&cloud_adm_dictionary_type%5Bitems%5D%5B4%5D%5BdictValue1%5D=fa-thumbs-o-down+text-danger&cloud_adm_dictionary_type%5Bitems%5D%5B4%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5B_token%5D=3PBJr_pPjHhAIB95N7PUReP5asrXsGwCILAxZLyGTUg deal:738
cloud_adm_dictionary_type%5Bitems%5D%5B0%5D%5BdictName%5D=w%C5%82asnee&cloud_adm_dictionary_type%5Bitems%5D%5B0%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B1%5D%5BdictName%5D=proklienckii&cloud_adm_dictionary_type%5Bitems%5D%5B1%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B2%5D%5BdictName%5D=telemarketing&cloud_adm_dictionary_type%5Bitems%5D%5B2%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B3%5D%5BdictName%5D=mailing&cloud_adm_dictionary_type%5Bitems%5D%5B3%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B4%5D%5BdictName%5D=www&cloud_adm_dictionary_type%5Bitems%5D%5B4%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B5%5D%5BdictName%5D=partner&cloud_adm_dictionary_type%5Bitems%5D%5B5%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B6%5D%5BdictName%5D=nowe+zrodlo&cloud_adm_dictionary_type%5Bitems%5D%5B6%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B7%5D%5BdictName%5D=Aaa&cloud_adm_dictionary_type%5Bitems%5D%5B7%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5B_token%5D=3PBJr_pPjHhAIB95N7PUReP5asrXsGwCILAxZLyGTUg"

And i want to make hashtag from that, something like i Don't know '462423dfdaak542634'. I need later to compare hashtags to see if the form was changed or not.

Is there a function in Javascript / Jquery which will make hashtag from a string ? I'm looking for the answer for few minutes and i can't find it :/ Maybe there is some other way to make it ? I have Symfony 2.4 application.

I have my form data serialized to string, for example:

"cloud_adm_dictionary_type%5Bitems%5D%5B0%5D%5BdictName%5D=Otwartabbb&cloud_adm_dictionary_type%5Bitems%5D%5B0%5D%5BdictValue1%5D=fa-comments-o+text-muted&cloud_adm_dictionary_type%5Bitems%5D%5B0%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B1%5D%5BdictName%5D=Wycena&cloud_adm_dictionary_type%5Bitems%5D%5B1%5D%5BdictValue1%5D=fa-comments-o+text-muted&cloud_adm_dictionary_type%5Bitems%5D%5B1%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B2%5D%5BdictName%5D=Negocjacje&cloud_adm_dictionary_type%5Bitems%5D%5B2%5D%5BdictValue1%5D=fa-comments-o+text-muted&cloud_adm_dictionary_type%5Bitems%5D%5B2%5D%5BisDefault%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B2%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B3%5D%5BdictName%5D=Wygrana&cloud_adm_dictionary_type%5Bitems%5D%5B3%5D%5BdictValue1%5D=fa-thumbs-o-up+text-primary&cloud_adm_dictionary_type%5Bitems%5D%5B3%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B4%5D%5BdictName%5D=Przegrana&cloud_adm_dictionary_type%5Bitems%5D%5B4%5D%5BdictValue1%5D=fa-thumbs-o-down+text-danger&cloud_adm_dictionary_type%5Bitems%5D%5B4%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5B_token%5D=3PBJr_pPjHhAIB95N7PUReP5asrXsGwCILAxZLyGTUg deal:738
cloud_adm_dictionary_type%5Bitems%5D%5B0%5D%5BdictName%5D=w%C5%82asnee&cloud_adm_dictionary_type%5Bitems%5D%5B0%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B1%5D%5BdictName%5D=proklienckii&cloud_adm_dictionary_type%5Bitems%5D%5B1%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B2%5D%5BdictName%5D=telemarketing&cloud_adm_dictionary_type%5Bitems%5D%5B2%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B3%5D%5BdictName%5D=mailing&cloud_adm_dictionary_type%5Bitems%5D%5B3%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B4%5D%5BdictName%5D=www&cloud_adm_dictionary_type%5Bitems%5D%5B4%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B5%5D%5BdictName%5D=partner&cloud_adm_dictionary_type%5Bitems%5D%5B5%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B6%5D%5BdictName%5D=nowe+zrodlo&cloud_adm_dictionary_type%5Bitems%5D%5B6%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5Bitems%5D%5B7%5D%5BdictName%5D=Aaa&cloud_adm_dictionary_type%5Bitems%5D%5B7%5D%5BdictActive%5D=1&cloud_adm_dictionary_type%5B_token%5D=3PBJr_pPjHhAIB95N7PUReP5asrXsGwCILAxZLyGTUg"

And i want to make hashtag from that, something like i Don't know '462423dfdaak542634'. I need later to compare hashtags to see if the form was changed or not.

Share Improve this question edited Sep 26, 2014 at 12:59 kix 3,31928 silver badges42 bronze badges asked Sep 26, 2014 at 10:35 Michal OlszowskiMichal Olszowski 8051 gold badge9 silver badges25 bronze badges 5
  • show some example of which string you want to convert to what? – Abdul Jabbar Commented Sep 26, 2014 at 10:36
  • 5 A whole 'few minutes' hey? Bet that was taxing. ;) – Moob Commented Sep 26, 2014 at 10:36
  • Abdul -> I have added informations which u wanted. – Michal Olszowski Commented Sep 26, 2014 at 10:40
  • hashtag is something else -__- what you need is a simple function which will return a unique hash value for your strings! – Abdul Jabbar Commented Sep 26, 2014 at 10:42
  • Similar question with answers: https://stackoverflow.com/questions/7616461/generate-a-hash-from-string-in-javascript-jquery – user989840 Commented Sep 20, 2017 at 16:22
Add a comment  | 

1 Answer 1

Reset to default 14

Here, you can use this simple hashing function:

function hashCode (str){
    var hash = 0;
    if (str.length == 0) return hash;
    for (i = 0; i < str.length; i++) {
        char = str.charCodeAt(i);
        hash = ((hash<<5)-hash)+char;
        hash = hash & hash; // Convert to 32bit integer
    }
    return hash;
}

See the DEMO here

发布评论

评论列表(0)

  1. 暂无评论