How to format a String or put mascara with Totalcross

3

I'm using the following way, but it does not work because of the compiler for using things from javax.swing.text.DefaultFormatter.

public string formatar(String text, String mask) throws ParseException {
    return new MaskFormatter(mask).valueToString(text);
}

I could not find a solution in the documentation available

    
asked by anonymous 31.05.2017 / 22:11

1 answer

2

I found a solution, but I do not know if it's the best one.

Using the mask from totalcross.ui.Edit itself, the method looks like this:

public string formatar(String text, String mask) {
    Edit edit = new Edit(mask);
    edit.setMode(Edit.NORMAL, true);
    edit.setText(text);
    return edit.getText();
}
    
01.06.2017 / 14:50