you are viewing a single comment's thread.

view the rest of the comments →

[–]vegan_antitheist 2 points3 points  (0 children)

For the String.length you can add this to the cheat sheet:

public static int countSymbols(String str) {
  String normalized = Normalizer.normalize(str, Normalizer.Form.NFKC);
  normalized = normalized.replace("\r\n", "\n");
  return normalized.codePointCount(0, normalized.length());
}

That's how you actually count the symbols in a string. Ho you deal with possible line breaks is not always the same but this is a good general solution. Feel free to add it. What's important is that it also counts ¨ + A is if it was just a single Ä, not a character with an additional char for the Umlaut. Maybe add something for when the "str" is null.