Search code examples
javastringjtextfieldcalculator

How to delete a character after a certain character


I am making this calculator and would like to delete everything after the equal sign and I have no Idea how this is what I have so far :

ansField.getText().indexOf("=");

I really have no Idea after this


Solution

  • This should point you in the right direction.

    indexOf will return the position of the = character in the String. You must use this expression (+1) as the sole argument to the substring method.

    It would be best to assign this expression once to a String then perform your operations.

       String value = ansField.getText();
       String modifiedValue = value.//Do substring using indexOf