I was wondering which of the best ways to turn a string (such as a message header) into a descriptive URL. the easiest way that comes to mind is to use a regular expression, for example:
public static Regex regex = new Regex( "\\W+", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace | RegexOptions.Compiled ); string result = regex.Replace(InputText,"_");
which turns
"my first (not yet very bad) cupcake !!:) .// \."
in
my_first_yet_not_so_bad_cupcake_
then I can delete the last "_" and check it against my db and see if it is still present. in this case, I would add a finite number to make it unique and double-check.
I could use it, say
http:
but is it safe? I have to check other things (like string length) is there any other, better method that you prefer? thanks
source share