4

This question is an extension to the question Is it OK to repost deleted answers as new answers? The conclusion was that it is not OK for an "answer that has basically the same content." What about if I want to start with a "clean slate" after correcting a mistake? I'm not trying to abuse the system.

Original post

I posted the following answer to this question:

This is gives all the indexes of a word in a text string but is a little more readable than @polygenelubricants' answer (and thus better for maintainability).

String text = "0123hello9012hello8901hello7890";
String word = "hello";

int index = word.indexOf(word);
while (index >= 0) {  // indexOf returns -1 if no match found
    System.out.println(index);
    index = word.indexOf(word, index + 1);
}

(Source)

Edit to original post

The original post was correctly downvoted because I never referenced text. The person who downvoted also left a comment (which I appreciated). I edited my answer with the corrected code:

This is gives all the indexes of a word in a text string but is a little more readable than @polygenelubricants' answer (and thus better for maintainability--see @StephenC's comment).

String text = "0123hello9012hello8901hello7890";
String word = "hello";

int index = text.indexOf(word);
while (index >= 0) {  // indexOf returns -1 if no match found
    System.out.println(index);
    index = text.indexOf(word, index + 1);
}

(Source)

Delete and Repost

However, editing the original post of course did not reverse the downvote. There were also two comments (the comment about the original mistake and my reply) that would not be useful to other people. I wanted to start with a "clean slate" so I deleted the original post and added this one:

Because of @StephenC's comment about code maintainability and my own difficulty in understanding @polygenelubricants' answer, I wanted to find another way to get all the indexes of a word in a text string. The following code (which is modified from this answer) does so:

String text = "0123hello9012hello8901hello7890";
String word = "hello";

int index = text.indexOf(word);
while (index >= 0) {  // indexOf returns -1 if no match found
    System.out.println(index);
    index = text.indexOf(word, index + 1);
}

This new post is essentially the same as the edited version of my original post. However, it doesn't contain the original mistake, the downvote, and the old comments.

1
  • 1
    Users > 10k rep will see the deleted answer as well
    – user4639281
    Commented Jun 17, 2015 at 4:56

2 Answers 2

4

The answer of the previous question is still valid : thou shall not delete a downvoted answer to repost the same as a new one after fixing some mistakes. You risk a ban for doing so.

The correct way when an answer of yours gets downvotes because of a stupid error is :

  • delete it immediately to stop it receiving downvotes (optional but efficient to stop downvotes)
  • fix the mistakes and all the remaining parts that would need cleaning
  • undelete it (if you first deleted it ;-) )
  • notify commenters that said it was wrong that you fixed it

It is often enough to have some users that downvoted because it was wrong to look at the comment you sent them, look the fixed answer and retract the down vote if the error was the main cause. But that's why I advise you to make it a really better post : give attention to spelling, syntax and formatting. If it is still a poor post, there are chances that downvoters won't retract their votes.

To make a complete answer, there's only one case when you can delete an answer (be it downvoted or not) and post a new one : if you post a completely different solution. But clearly it is not the case here, because the code is roughly the same.

0

You cannot IMO, take this out of context.

If your answer was the only answer on a post there would be no reason to do this. The OP would recognise your downvoted and corrected answer, accept it and chances are that you will have a positive score over time. Hence leave it alone.

If your answer is one of bunch of answers and none of them is accepted (yet) you should see this not as a false start but a start where you slipped: you'll have a problem finishing first, unless you are really much better. But the race is not going to be rerun because you slipped, and you should IMO not ask for an opportunity to restart. There will be other races cq. other answers you can post. Hence update your post until it is in perfect shape for the race. You are running the marathon here, not the 100 meter so you have time to catch up.

If your answer is a new one and there is an accepted high voted one, accept the fact that you tried to come up with an alternative and failed. Chances are extremely slim that the one or two downvotes are going to make a difference. For the OP to change the accept is a rare occasion (unless your answer merits it and that doesn't depend on the downvotes). Your answer will be seldom read anyway, so you should not worry about the downvotes. Hence let it be.

The irrelevant comments are even less likely to be read, and if your answer does get in the picture because of high upvotes (+10 or so), you could consider pinging the writers and ask them to remove them as no longer relevant.

With deletion the edit history is gone for all but 10K+ users and that is sometimes instructive to read.

So the basic answer based on these cases is no: you should not delete and repost.


In addition your post doesn't seem to answer the original question which was:
Java: method to get position of a match in a String? The emphasis on "a" is mine. This asks for a sinle match. Your answer is about getting all indexes. That is an answer to a different problem.

Now you might want to delete the answer and post it as an answer on a question that asks for all positions. Or you can create that question yourself if it doesn't exist yet and post your answer there.

But that possibility is answering a different question than you posted here on meta.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .