Find text between two strings : String « Data Type « Java






Find text between two strings

    
 
import java.util.Date;
import org.apache.commons.lang.StringUtils;
 
public class Main {
    public static void main(String[] args) {
        String helloHtml = "<html>" +
                "<head>" +
                "   <title>Hello World from Java</title>" +
                "<body>" +
                "Hello, today is: " + new Date() +
                "</body>" +
                "</html>";
        
        String title = StringUtils.substringBetween(helloHtml, "<title>", "</title>");
        String content = StringUtils.substringBetween(helloHtml, "<body>", "</body>");
        
        System.out.println("title = " + title);
        System.out.println("content = " + content);
    }
}
 

   
    
    
    
  








Related examples in the same category

1.Get String hash code
2.To extract Ascii codes from a String
3.LengthOf - show length of things
4.Show string escapesShow string escapes
5.Convert string to char array
6.See if Strings are shared in Java
7.If a string is empty or not
8.Count word occurrences in a string
9.Check for an empty string
10.Remove leading and trailing space from String
11.Reverse a string
12.Put quotes around the given String if necessary.
13.Starts With Ignore Case
14.Repeat String
15.implements CharSequence