Generate unique string from post header like stackoverflow

How can I generate a unique string from the post header in my C # code? Similar to the one that appears in the URL of this post.

+2


source to share


5 answers


The string doesn't have to be unique, in fact: if you check the url of this post:

http://stackoverflow.com/questions/1467402/generate-a-unique-string-from-the-post-title-like-stackoverflow

      

The "real" unique part is the number - here 1467402

: it looks like the question ID in the database; probably some kind of auto-increment / sequence that is provided by a unique database server.


In fact, you can try checking for yourself if the "title" part is important: go to this URL:

http://stackoverflow.com/questions/1467402/glop

      



Even though the "title" part is clearly not here, this URL falls into this entry; -)


The "title" displayed in the URL is here for two reasons:

  • more friendly urls of course
  • more search engines / better for linking links.

To generate this, you need to do a couple of things:

  • replace non-ascii characters; for example, "é" is likely to be translated into "e"
  • replace other characters that you cannot replace nicely with "-" as word separator.
+17


source


This is a very broad question.



Most of the time, when I need to identify something unique, I use Guid .

+2


source


They just replace spaces with dashes, but then you'll want to make sure they don't exist yet.

If it exists, just add the number to the end.

You will notice that they have a number in front of the unique string, which will reduce the chance of collisions.

You can create this based on the Julian date (number of days in a year) and the year, for example.

+1


source


Phil Haack posted this thread in this post .

You can do something similar, but more general (add an increasing number to the end).

0


source


If post titles are unique, just use them. Or you can create a message digest signature.

see http://www.obviex.com/samples/hash.aspx for a long answer.

0


source







All Articles