Search code examples
javastringrepeat

Best way to check repetition of a char in a string?


Suppose I wanna know how many times this . is repeated in 127.0.0.1 String.


Solution

  • this not an android problem it's a java problem any way you have to get the text from the EditText as String and then check for the count of the .(Point) in the string

    String line = EditText.getText.toString()
    int count = line.length() - line.replace(".", "").length();
    

    now if count is more than 1 it will make crash so give the user messae and stop the process else do what you want you are save