Created
April 14, 2017 01:27
-
-
Save Natumsol/dcdd4b614bb969c679b97c0221018838 to your computer and use it in GitHub Desktop.
将句子中单词首字母大写
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function upperFirstChar(str) { | |
| // replace的第二个参数可以为函数,第一个为匹配到的字符串,第二个为匹配在原字符串中的索引,第三个为原字符串 | |
| return str.replace(/\w+/g, function(match, offset, string){ | |
| return match[0].toUpperCase() + match.slice(1); | |
| }); | |
| } | |
| console.log(upperFirstChar(" hello, world my World hehe")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment