How to check how many letters are in a string in java?

前端 未结 4 1642
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-14 18:03

How do you check how many letters are in a Java string?

How do you check what letter is in a certain position in the string (i.e, the second letter of the string)?

4条回答
  •  独厮守ぢ
    2020-12-14 18:07

    If you are counting letters, the above solution will fail for some unicode symbols. For example for these 5 characters sample.length() will return 6 instead of 5:

    String sample = "\u760c\u0444\u03b3\u03b5\ud800\udf45"; // 瘌фγε

提交回复
热议问题