【发布时间】:2015-04-04 20:15:38
【问题描述】:
如何将字符串人性化?基于以下标准:
- 删除前导下划线(如果有)。
- 如果有的话,用空格替换下划线。
- 第一个单词大写。
例如:
this is a test -> This is a test
foo Bar Baz -> Foo bar baz
foo_bar -> Foo bar
foo_bar_baz -> Foo bar baz
foo-bar -> Foo-bar
fooBarBaz -> FooBarBaz
【问题讨论】:
-
我猜如果是 CamelCase,应该不管它吗?带破折号的单词的原理相同。但第一个字符应始终大写。我进行了编辑。
标签: javascript string humanize