Question:

Java Text Search? or filter?

by  |  earlier

0 LIKES UnLike

i have a little (very little) java program that just prints a webpage... like text with tags, im using it to get some info which is located in a tag with <whatever> Heres the info </whatever> how do i make it print only what starts with <whatever> and ends with </whatever>?

 Tags:

   Report

1 ANSWERS


  1. Using the java.lang.String methods:

    int startTag = YourString.indexOf(&quot;&lt;whatever&gt;&quot;)  --&gt; Finds the index of open tag

    int endTag = YourString indexOf(&quot;&lt;/whatever&gt;&quot;) --&gt; Finds the index of the close tag

    int startData = startTag + 10 --&gt; Offset index to length of tag, since we want to get the substring starting from the end of the &lt;whatever&gt; tag (you&#039;ll have to adjust for the length of the tag name)

    String info = YourString.substring(startData,endTag-1) --&gt; Get the data string between the tags

Question Stats

Latest activity: earlier.
This question has 1 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.