Normalizer.Form.NFD : Normalizer « java.text « Java by API





Normalizer.Form.NFD

 


import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.Normalizer;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Main extends JFrame {
  public Main() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    JPanel pnl = new JPanel();
    pnl.add(new JLabel("Enter text"));
    final JTextField txtText;
    txtText = new JTextField("to be removed");
    pnl.add(txtText);

    JButton btnRemove = new JButton("Remove");
    ActionListener al = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        String text = txtText.getText();
        text = Normalizer.normalize(text, Normalizer.Form.NFD);
        txtText.setText(text.replaceAll("[^\\p{ASCII}]", ""));
      }
    };
    btnRemove.addActionListener(al);
    pnl.add(btnRemove);
    add(pnl);
    pack();
    setVisible(true);
  }

  public static void main(String[] args) {
    new Main();
  }
}

   
  










Related examples in the same category

1.Normalizer: normalize(CharSequence src, Form form)