How to Format a String or Put Mask with Totalcross

Asked

Viewed 68 times

3

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 couldn’t find a solution in the available documentation

1 answer

2


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

Using the mask of totalcross.ui.Edit itself, the method is 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();
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.