zoukankan      html  css  js  c++  java
  • 大小写字母的转换

    String中有这些个方法:

    1、toUpperCase() 将字符串中的每个字母转为大写

    2、toLowerCase()将字符串中的每个字母转为小写

    通过这两个函数,我们就可以对英文字符串进行大小写的转换。

            var str = 'tracy';
    
            toUpper( str );
    
            // 转为大写
    
            function toUpper( str ){
                var result = str.toUpperCase();
                console.log(result);
            }
            // 转为小写
    
            var sstr = 'LEE';
    
            toLower( sstr );
    
            function toLower( sstr ){
                var result = sstr.toLowerCase();
                console.log(result);
            }

    一个题目:将传入的一个字符串(包含多个单词),将每个单词的首字母转为大写。

            // 将字符串中的每一个单词的首字母都转为大写
    
            var words = "i am a student.";
    
            changeFirstLetter( words );        
    
            function changeFirstLetter( words ){
                var arr = words.split(" ");
                for( var i = 0; i < arr.length; i++ ){
                    arr[i] = arr[i].charAt(0).toUpperCase() + arr[i].slice(1);
                }
                return console.log(arr.join(" "));
            }
  • 相关阅读:
    年薪百万必备能力
    二叉搜索树
    字符串和字符串模式匹配
    2006最后寄语
    “豆瓣”式推荐
    什么是LOMO?
    大国崛起
    马季之死
    时间的价值(The Value Of Time)
    我读雅虎的“花生酱宣言”
  • 原文地址:https://www.cnblogs.com/tracylyx/p/upper-lower.html
Copyright © 2011-2022 走看看