I’m migrating a legacy PHP application to .net, and one of the requirements is that the URLs stay exactly as before.
To generate friendly URLs the legacy application uses str_word_count, I was wondering if there is a port of this function to C#?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Okay here’s my “bad C#” example (mimicking PHP in the mixed return type). It’s a fairly trivial implementation leveraging .NET’s Regular Expressions.
So the function will return a
Dictionary<int,string>if you chooseASSOC, astring[]if you chooseARRAYand a simpleintif you chooseNUMBER.An example (I copied PHP’s example here
But, I’d like to add a note here: Don’t return objects. It works aok with PHP because it’s not a strongly typed language. Really, you should be writing individual versions of the function to cater for each different format. Anyways, that should get you started 🙂
Output: