Java – How to separate numbers and characters on a String [closed]

I have a generic string like a Serial Number
Example: ب12345678

And I want to write a method that takes String I wrote above and display it to me in the output as the following string
ب/ begin number 12-345678

Please guide me on how to make a generic parser for this type of Serial Number

Answer

To solve the issue you have with the code you have given to me in the comments this is where I end up

public class myClass { 
    public String myMethod(){
        String newString = "";
        Customer customer= new Customer(); 
        String oldString= customer.getPerson.getSerialNumber(); 
        // oldString = "A12345678" 
        if (oldString != null && StringUtils.isEmpty(oldString)){ 
            if (oldString.length()==9){ 
                // get oldString and convert to newString = A / 12-345678
                newString = oldString.substring(0, 1) + " / " + oldString.substring(1, 3) + "-" + oldString.substring(3);
            } 
        } 
    } 
}

newString is now A / 12-345678

Leave a Reply

Your email address will not be published. Required fields are marked *