1

Possible Duplicate:
URL Slugify alrogithm in C#?

I would like to convert a string like this:

Testing this on-the-test-forum (please/remove) if possible. test: test, "abc"

To a string like this:

testing-this-on-the-test-forum-please-remove-if-possible-test-test-abc

Does anyone have any ideas on the simplest type of function that I could use for this. What I am looking for is something very simple as I need to use this function later within LINQ.

3
  • 3
    This is called a slug. Commented Jul 28, 2011 at 8:23
  • This is starting to look a lot more complicated than I expected :-( Commented Jul 28, 2011 at 8:29
  • @Marife just take the code from the duplicate and you will be fine Commented Jul 28, 2011 at 8:36

1 Answer 1

0

Your easiest approach would seem to be identifying the characters that you do want in the returned string and code it based on these. So, in pseudocode:

newstring = "";

foreach(character in newstring.tolower)
    if(character in allowedcharacters)
        newstring+=character;
    else
        newstring+="-";

return newstring.replace("--","-");

That should be a start for you.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.