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

NullPointerException : android editText

java android android-fragments nullpointerexception android-edittext

I've been following this this tutorial to create a date picker , but I keep having a nullpointerexception when setting the value of edit_text, here some parts of my code :

What is the default line spacing of UILabel in iOS 6 vs iOS 7?

ios ios7 uilabel nsattributedstring uifont

As shown in this question, the default line spacing of multiline labels changed in iOS 7. In fact, it appears iOS 7 now uses a default line spacing of 0 in this case.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.