The objective of this code is to split a string that is over 60 characters into two separate strings, cutting them at a space.
So, the issue that I'm having is that, in the second 'for' loop, the value for 'a' is equal to the 'str' in the methods parameters, and I can't figure out why.
Any help would be appreciated.
String textPanel_2;
String textPanel_3;
String textPanel_4;
String textPanel_5;
public String correctText(String str)
{
String textPanel_1 = str;
String remainder = str;
for (int a = 60; a > 0; a--)
{
if (str.charAt(a) == ' ')
{
textPanel_1 = str.substring(0, a);
remainder = str.substring(a + 2, str.length());
break;
}
}
if (remainder.length() < 60)
{
for (int a = remainder.length() - 1; a > 0; a--)
{
if (remainder.charAt(a) == ' ')
{
textPanel_2 = remainder.substring(0, a);
remainder = remainder.substring(a + 2, str.length());
}
}
}
return textPanel_1;
}
