Finding all uppercase letters of a string in java

前端 未结 10 1115
后悔当初
后悔当初 2021-01-12 14:28

So I\'m trying to find all the uppercase letters in a string put in by the user but I keep getting this runtime error:

Exception in thread \"main\" java.lan         


        
10条回答
  •  长发绾君心
    2021-01-12 15:12

    The simplest way I know is to use regex replacement.

    isUp = x.replaceAll("[^A-Z]", "");
    

    In simple terms, this uses a regular expression which matches any character which is not in the A-Z range, and replaces it with an empty string.

提交回复
热议问题