0

I am building a CMS that uses query strings to show different editors.

Example:

editors.php?editor=Articles

I need to make the word article singular for a button that say "New Article". I want to use the same query string editor value to avoid a big if statement.

I need to do it with javascript. It is only going to run on my 4 pre-defined strings.

basically this: if(string has s at the end){drop the s}

0

2 Answers 2

1

There is no good way to programmatically convert plurals into singulars, or vice versa, in English, because there is no hard and fast rule on how words are pluralized. You need some sort of lookup table--perhaps in the form of if statements, as you suggested. Or maybe you can use a singular word in your URL.

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

1 Comment

I only have four strings: Articles, Users, Media, Navigation. I need "Articles" and "Users" to drop the "s" at the end to add to a button that adds new items. "New Article" instead of "New Articles". It all really comes down to the fact that I don't want to change a lot of other functions just to render one button right. basically this: if(string has s at the end){drop the s}
0

I always go here when I need to emulate a PHP function in javaScript.
And I believe you would want this function.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.