Title Case a Sentence
2017-03-03 12:33
155 查看
For the purpose of this exercise, you should also capitalize connecting words like "the" and "of".
思路:1.将字符串全部转换为小写,然后转为数组var array=str.toLowerCase().split(" ");
2.遍历数组,将数组中字符的第一个字符转换为大写toUpperCase(),然后[b]substring(1,array[i].length),截取字符串中的其余位。[/b]
[b][b]3.将数组转换为字符串,并返回[/b][/b]
function titleCase(str) {
var array=str.toLowerCase().split(" ");
for(var i=0;i<array.length;i++){
array[i]=array[i][0].toUpperCase()+array[i].substring(1,array[i].length);
}
var string=array.join(" ");
return string;
}
titleCase("I'm a little tea pot");
相关文章推荐
- JavaScript实现-句中单词首字母大写-Title Case a Sentence
- js基础算法之 字符串首字母全大写Title Case a Sentence
- Bonfire: Title Case a Sentence 句子中单词首字母大写
- FCC算法:五、Title Case a Sentence--句中单词首字母大写
- FreeCodeCamp学习--Title Case a Sentence
- FreeCodeCamp学习--Title Case a Sentence
- Warning: Could not find an exact (case-sensitive) match for 'Title'.
- T-SQL 基于列的逻辑表达式 (CASE)
- JS实现title标题栏文字不间断滚动显示效果
- switch case 忘记 break
- Mybatis Case Study收集整理
- MSSQL 2005 SQL利用Case When Then多条件判断
- Max length of title attribute in html
- UIButton上使用UIEdgeInsetsMaketitle跟图片对齐
- switch...case...
- android全屏去掉title栏的多种实现方法
- oracle case then用法
- Case用法
- easyui获取当前点击对象tabs的title
- sql解惑2(谜题45)join比case when要快?