As I mentioned in my comment above, if you want to do any serious manipulation of HTML content, you should be using an HTML/XML parser, rather than base string functions. That being said, for your particular string, you can search for the following pattern and just replace with empty string:
<td class=\"tg-s6z2\">@w1d1p7</td>\n
Code snippet:
String str = "<tr>\n" +
"<td class=\"tg-s6z2\">@w1d1p7</td>\n" +
"<td class=\"tg-s6z2\">@w1d2p7</td>\n" +
"<td class=\"tg-s6z2\">@w1d3p7</td>\n" +
"<td class=\"tg-s6z2\">@w1d4p7</td>\n" +
"<td class=\"tg-s6z2\">@w1d5p7</td>\n" +
"<td class=\"tg-s6z2\">@w1d6p7</td>\n" +
"</tr>\n";
str = str.replaceAll("<td class=\"tg-s6z2\">@w1d1p7</td>\n", "");
System.out.println(str);
Note that String#replaceAll()
has regex capability, so if your replacing requirements were more complex than this, we probably could also accommodate them.
Output:
<tr>
<td class="tg-s6z2">@w1d2p7</td>
<td class="tg-s6z2">@w1d3p7</td>
<td class="tg-s6z2">@w1d4p7</td>
<td class="tg-s6z2">@w1d5p7</td>
<td class="tg-s6z2">@w1d6p7</td>
</tr>
Demo here:
Rextester
solved Remove whole line by character index [closed]