Is there a simple way to convert a string to title case? E.g. john smith
becomes John Smith
. I'm not looking for something complicated like John Resig's solution, just (hopefully) some kind of one- or two-liner.
相关问题
- Is there a limit to how many levels you can nest i
- How to toggle on Order in ReactJS
- void before promise syntax
- Keeping track of variable instances
- Can php detect if javascript is on or not?
As full featured as John Resig's solution, but as a one-liner: (based on this github project)
Prototype solution of Greg Dean's solution:
ES 6
else
Here is my function that is taking care of accented characters (important for french !) and that can switch on/off the handling of lowers exceptions. Hope that helps.
Here’s my function that converts to title case but also preserves defined acronyms as uppercase and minor words as lowercase:
For example:
Without using regex just for reference: