Searching for a digit and delete it in my int variable

时间:2016-03-04 17:48:23

标签: java variables int digit

I want to search a digit in my int variable and delete it.

Here is little part of the code (not finished, because i'm still on the implementation). I noticed that there are many use cases. So do you know an easier way to delete the digit?

public int getStringtoIntForEthType(int OxAB){
        String myInt = Integer.toString(OxAB);
        if(Integer.toString(OxAB).contains("x")){
            myInt = myInt.substring(2);
        }
        StringBuilder myIntBuilder = new StringBuilder(myInt);

        for(int a = 0; a<=myInt.length();a++){
            if(a-1 < 0 && myIntBuilder.charAt(0)!=0 && myIntBuilder.charAt(a)==0){

            }
        }

        return Integer.parseInt(myIntBuilder.toString());
    }

1 个答案:

答案 0 :(得分:1)

To delete all existence of that Digit from the number here is a function :-

public int DeleteDigit(int number, int numberToDel)
{
    String Num = "" + number;
    Num = Num.replace(numberToDel + "", "");

    if(Num.length != 0)
        return Integer.parseInt(Num);
    return 0;
}

this would return an integer without the digit