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

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Parallel Programming Primer II: Multiprocessing and Multithreading

How to Add Text-to-Speech to Donations to Your Stream

The Truth On Trump’s Recent Firing Of My Father

Complex machine integration with MocDoc’s laboratory management system

Async IO in Today’s Programming Languages

Cloud Design Patterns: Part 1

Software Development Trends 2021: Latest research data

Run unpublished Spark notebooks in Azure Synapse

Cover image

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
Code Factory

Code Factory

More from Medium

How Java Works

Annotations In Java

Root of Number (Java solution)

Java Reflection, part 1: primitives, arrays, classes