hi, ich habe ein problem bei folgender methode:
wenn ich den substring ersetzen will komme ich in eine endosschleife, wodurch das joptionpane nie angezeigt wird. lustigerweise habe ich aber die gleiche for-schleife schon etwas weiter oben in der methode, und die endet nicht in einer endlosschleife. kann mir jemand helfen?
Java:
public void searchString()
{
int position = 0;
String output = "";
boolean replace;
String mainString = enterString("Enter the String you want to search in!");
String subString = enterString("Enter the String you want to search!");
for (int i = 0; (position = mainString.indexOf(subString, position)) > -1; i++ )
{
position += subString.length();
output += "[" + position + "-" + (position + subString.length()) + "]\n";
}
JOptionPane.showMessageDialog(f, output, "string searched", 1);
replace = Utils.yesNo(f, "Do you want to replace the sub-String?", "replace?");
if(replace)
{
position = 0;
String replacement = enterString("Enter the String for the replacement!");
for (int i = 0; (position = mainString.indexOf(subString, position)) > -1; i++)
{
mainString.replace(subString, replacement);
}
JOptionPane.showMessageDialog(f, mainString, "String with replaced subString", 1, null);
}
}