Dear stackoverflow members,
I have a small problem,
I want to replace some characters in my string with other in java, and my code to do it is as follow,
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
jComboBox1.removeAllItems();
String str = new GenericResource_JerseyClient().getlist();
String [] temp = null;
temp = str.split(",");
temp[1]=temp[1].replaceAll("'", "");
temp[1]=temp[1].replaceAll(" ", "");
temp[1]=temp[1].replace("[", "");
temp[1]=temp[1].replace("]", "");
for(int i =0; i < temp.length ; i++)
{
jComboBox1.addItem(temp[i]);
} // TODO add your handling code here: // TODO add your handling code here:
// TODO add your handling code here
}
As it can be seen from the above code i replace “‘”,”[“,”]”,and empty space with nothing.
As it can be also seen from the code that i split the string into two. In the part of string after , the code works well but the part of string before , the code doesn’t seem to work properly.
i have also attached a copy of the dropdown list output in the client side.
Any help would be very much appreciated on how to remove [ and ‘ from the string.
Cheers.
Perform all your replacements BEFORE splitting the string. This is better than executing the same code in a loop.
For example: