Here is a piece of code that I use, I can not find a solution, how to make all the values ​​that are written (inserted in my case) from the new line are replaced with commas, but in the case of two in a row, or more \\s so that only one comma is replaced, not two or more.

  JTextPane chId = new JTextPane(); JButton runQ = new JButton("Generate 'SELECT' Query"); runQ.addActionListener(new ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent e) { String text = chId.getText().replaceAll("\\s", ","); chId.setText(text); if (moreThenOne.isSelected()) { selectQ.setText("SELECT id FROM table WHERE id IN (" + chId.getText() + ");"); } else { selectQ.setText("SELECT id FROM table WHERE id = " + chId.getText() + ";"); } } }); 

    1 answer 1

    Add +

     String text = chId.getText().replaceAll("\\s+", ","); 
    • Thank! And then I went to the forest by adding .replaceAll(",,", ","); - Eik