hi everybody. I was wondering which is the best way to turn a string (e.g. a post title) into a descriptive URL. the simplest way that comes to mind is by using a regex, such in:
public static Regex regex = new Regex(
"\\W+",
RegexOptions.IgnoreCase
| RegexOptions.CultureInvariant
| RegexOptions.IgnorePatternWhitespace
| RegexOptions.Compiled
);
string result = regex.Replace(InputText,"_");
which turns
"my first (yet not so bad) cupcake!! :) .//\."
into
my_first_yet_not_so_bad_cupcake_
then I can strip the last "_" and check it against my db and see if it's yet present. in that case I would add a trailing number to make it unique and recheck.
I could use it in, say
http://myblogsite.xom/posts/my_first_yet_not_so_bad_cupcake
but, is this way safe? should i check other things (like the length of the string) is there any other, better method you prefer? thanks