Get SubString Between Tags in Java | Code Factory

package com.codeFactory;import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang3.StringUtils;
/**
* @author code.factory
*
*/
public class SubstringBetween {
public static void main(String... args) throws IOException {
File file = new File("TestHTML.html");
String htmlStr = FileUtils.readFileToString(file);
String title = StringUtils.substringBetween(htmlStr, "<title>", "</title>");
System.out.println("Title : " + title);
String[] tds = StringUtils.substringsBetween(htmlStr, "<td>", "</td>");
for (String td : tds) {
System.out.println("Td : " + td);
}
}
}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Code Factory</title>
</head>
<body>
<table>
<tr>
<td>One</td>
<td>Two</td>
</tr>
<tr>
<td>Three</td>
<td>Four</td>
</tr>
</table>
</body>
</html>
Title : Code Factory
Td : One
Td : Two
Td : Three
Td : Four

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store