Counting upper and lower case characters in a string

后端 未结 7 581
礼貌的吻别
礼貌的吻别 2020-12-19 03:25

First off, I know this is far from professional. I\'m trying to learn how to work with strings. What this app is supposed to do is take a simple text input and do a few thi

7条回答
  •  粉色の甜心
    2020-12-19 04:17

    You can use match() and regular expressions.

    var str = "aBcD"; 
    var numUpper = (str.match(/[A-Z]/g) || []).length;    // 2
    

提交回复
热议问题