js字符串字母大小写互转

悠悠 2022-03-31 07:58 310阅读 0赞

需求:把一个字符串中的大写字母转为小写,小写字母转大写

  1. function parseStr (str){
  2. var result = '';
  3. for(var i= 0;i<str.length;i++){
  4. var temp = str.charAt(i);
  5. var code = temp.charCodeAt();
  6. if('a' <= temp && temp <= 'z'){
  7. temp= String.fromCharCode(code-32);
  8. } else if('A' <= temp && temp <= 'Z'){
  9. temp= String.fromCharCode(code+32);
  10. }
  11. result += temp;
  12. }
  13. return result;
  14. }

发表评论

表情:
评论列表 (有 0 条评论,310人围观)

还没有评论,来说两句吧...

相关阅读