First of all, sorry if code looks messy. I have to make a To do list on Java where the user can add and delete chores, without using regex. I can only use methods from the String class. Every chore entered should end with "\n":
list = list + addedChore + "\n"
If user wants to delete the first chore for example:
endofChore1 = list.indexOf("\n", 0);
chore1 = list.substring(0, endofChore1);
chore1 = "";
What i tried to do was to get the index of the first \n and make it a substring starting from index 0 to the index of the first \n, and finally replace that substring with an empty string that way it deletes the chore from the list. However, it is not working. What can I do to fix this? Thank you.
Edit: This is what i wrote to delete any given chore. I don't see what's wrong with it.
int choreToDelete; // number associated with chore user wants to delete
int begin = 0;
int i = 0;
int end;
String stringToDelete;
if (choreToDelete >= 1 && choreToDelete <= numberOfChores){
while (i < choreToDelete - 1) {
end = list.indexOf("\n", begin);
begin = end;
i = i + 1;
}
}
stringToDelete = list.indexOf("\n", begin);
list = list.substring(stringToDelete);
listand b) made thechore1 = list....instruction a noop.