Pergunta

I have String like

<div style="width:100%"><table><tr class="abc"><td class="tdcss">some data</td></tr></table> 
</div>

strong text I want to remove all class and style tags(I mean css and script tags). I want the my string like

<div>
<table>
<tr>
<td>
some data
</td>
</tr>
</table>
</div>

I have to do this by using java. can any one help me with this....

Foi útil?

Solução

If the string is fairly small, one option you have is to use regular expressions. String.replaceAll accepts a regular expression and a replacement string. So you could try something like yourString=yourString.replaceAll("style=\\".+?\\"", ""); yourString=yourString.replaceAll("class=\\".+?\\"", "");

Try http://gskinner.com/RegExr/ It has a great regular expression builder asnd evaluator on a sample string.

Outras dicas

1) Find the index of Style 2) Then find the next index of "" then remove the String between these two indices. Similarly for Class.

There is no other way provided by String. You have to parse the String and use replace()or substring() methods

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top