I have an ArrayList that is built from posts in a forum, each entry is a post. When I am building the entry I am replacing all elements with the string "Image[x]". After the array list is filled I want to go back and replace all instances of "[x]" with an incrementing integer.
I am building my array list using this code:
Elements wholePosts = doc.select("div.post_body");
for (Element wholePost : wholePosts) {
Elements texts = wholePost.select("div[itemprop=commentText]");
for (Element text : texts) {
String nobr = text.html().replaceAll("(?i)<br[^>]*>", "newlineplaceholder");
String formatted1 = nobr.replaceAll("<img src=.*?>", "Image[x]");
Document finalPost = Jsoup.parse(formatted1);
String almostfinalText = finalPost.text();
String finalText = almostfinalText.replace("newlineplaceholder", "\n");
datumList.add(finalText);
}
I have tried to replace the string and increment it in the above code but it only increments for each post element, so if there are multiple images in a post, post 1 would contain "Image1, Image1" and post 2 would contain "Image2, Image2". What I am looking for is for post 1 to contain "Image1, Image2" and post 2 to contain "Image3, Image4"