Question

Write a method extractTitle that takes a string as input parameter representing IMDB movie information (written...

Write a method extractTitle that takes a string as input parameter representing IMDB movie information (written in XML style), and extracts all of the text between the tags and . Your method can assume that there will be at most one movie title inside the input string.

Example: extractTitle("Split (2017)6375308") returns "Split (2017)"

0 0
Add a comment Improve this question Transcribed image text
Answer #1
public class ExtractTitle {

    public static void main(String[] args) {
        System.out.println(extractTitle("<item><title>Split (2017)</title><meta><imdb>6375308</imdb></meta>"));
    }

    public static String extractTitle(String data) {
        int startIndex = data.indexOf("<title>");
        if (startIndex == -1) return "";
        int endIndex = data.indexOf("</title>", startIndex);
        if (endIndex == -1) return "";
        return data.substring(startIndex + 7, endIndex).trim();
    }
}

Add a comment
Know the answer?
Add Answer to:
Write a method extractTitle that takes a string as input parameter representing IMDB movie information (written...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT