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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -