c# - Create my own Unique ID -
i trying create own unique id in c# each document in nosql database not sure how that?
my example uid ######.entitytype@######.contextname.worldname
the hashes alphanumeric characters.
making assumptions here, generate guid, split guid on hyphen, use parts of guid in user name.
use string builder concatenate all.
here's bit of sample code give idea (untested):
guid g = guid.newguid(); string[] parts = g.tostring().split('-'); stringbuilder sb = new stringbuilder(); sb.append(parts[0]); sb.append("entitytype@"); sb.append(parts[1]); sb.append(".contextname.worldname"); string id = sb.tostring();
this won't globally unique, should give range of uniqueness scenario.
to match hash lengths above this:
string gstring = guid.newguid().tostring().replace("-",""); stringbuilder sb = new stringbuilder(); sb.append(gstring.substring(0,6)); sb.append("entitytype@"); sb.append(gstring.substring(6,6)); sb.append(".contextname.worldname"); string id = sb.tostring(); messagebox.show(id);
Comments
Post a Comment