Java String Comparison with html tags

I have two Strings as follow:

String input="<tr><td>Hello world</td></tr>";
String output="<body><tr><td>Hello world</td></tr></body>";

I want to compare the two strings and need to remove the <body></body> tags from the output string if the input string doesn't contain <body> tag. The string may be of any length.

How to compare and replace the output string based on input string? <body> tag may be anything like <body ></body > or < body>< /body>,etc.

Need to find the tag and replace it based on input string.

Answers


static String[] combinations = new String[] {
    "<body>","</body>","< body>","< /body>","<body >"
};

for (int i = 0; i < combinations.length; i++) {
    if (!input.contains(combinations[i])) {  
        output = output.replace(combinations[i], "");    
    }    
}

 String resultingOutput = "";
 if( !(input.contains("<body>")) && !(input.contains("</body>")) ){
      resultingOutput = output.replace("<body>", "").replace("</body>","");
 }

Need Your Help

How can I add a 'test service' page to a WCF Webservice in VB.Net

vb.net wcf

I am building a Web service using WCF as a way to provide access to data within my VB.Net application.

looping through a generic list with foreach

c# foreach

I'm trying to learn about generics, and I'm trying to make my own generic list class.

Registeting interceptors after Component registration in Castle

c# castle-windsor interceptor castle facilities

I have a facility which needs to register an interceptor and then register this interceptor against