简体   繁体   中英

Stripping Html content from response

We need to remove particular string from HTML response created by server through JAVA code. For example, I need to remove comment tag from the HTML response before sending the response to client. Any help will be appreciated..

Try this

int lowerIndex = <response String>.indexOf('<!--'));
int upperIndex = <response String>.indexOf('-->'));

You will get starting and ending indexes of the comment tag. Then you can do

String newString = <responseString>.substring(0,lowerIndex)+<responseString>.substring(upperIndex)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM