C#中如何转换字符串中的唯一ID [英] C# how to convert string in to unique ID

查看:322
本文介绍了C#中如何转换字符串中的唯一ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们假设我们有字符串名称=stackoverflow.com;

如何将此字符串INT转换为一个唯​​一的ID或某种哈希的。 (无MD5,因为它太大了),它不应该是随机

我会想有这样的事情

请注意字符串本身太大了,我想知道如果字符串可以写短。在字母,数字和符号的组合

  

f¤k^§〜7天?Æ

解决方案

这是不限制你的域名是不可能的。有无穷多个字符串和等都不能injectively映射到任何有限集。因此,唯一性是不可能的。

如果你真的想为字符串的唯一标识符,使用字符串本身。

let assume we have string name = "stackoverflow.com";

how to convert this string int to a unique ID or some sort of Hash. (no md5 because its too big) and it should not be random

i will like to have something like this

Please note string itself is too big I would like to know if the string can be written shorter. in an combination of letters, numbers and symbols

f¤k^§~7d?Æ

解决方案

This is impossible without restricting your domain. There are infinitely many strings and so can't be mapped injectively into any finite set. Therefore, uniqueness is impossible.

If you really want a unique identifier for string, use the string itself.

这篇关于C#中如何转换字符串中的唯一ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆