How to format a String or mask with Totalcross

Question:

I'm using it as follows, but it doesn't work because of the compiler using things from javax.swing.text.DefaultFormatter.

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

I didn't find a solution in the available documentation.

Answer:

I found a solution, but I don't know if it's the best one.

Using the mask from totalcross.ui.Edit itself, the method was as follows:

public string formatar(String text, String mask) {
    Edit edit = new Edit(mask);
    edit.setMode(Edit.NORMAL, true);
    edit.setText(text);
    return edit.getText();
}
Scroll to Top