简体   繁体   中英

Jquery Substring Replace

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}

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM