Counting upper and lower case characters in a string

后端 未结 7 600
礼貌的吻别
礼貌的吻别 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:09

    Use regular expressions.

    Example

    var s = "thisIsAstring";
    var numUpper = s.length - s.replace(/[A-Z]/g, '').length;  
    
    // numUpper = 2
    

    Se more at JavaScript replace/regex

提交回复
热议问题