1

Can someone please help me understand this bit of code with an example. I have been struggling just to get my head around this code.

URLResource file = new  URLResource("http://www.dukelearntoprogram.com/course2/data/manylinks.html");         
for (String item : file.words()) 
{    String itemLower = item.toLowerCase();       
  int pos = itemLower.indexOf("youtube.com");     


  if (pos != -1) {         
        int beg = item.lastIndexOf("\"",pos);    
        int end = item.indexOf("\"", pos+1);            
System.out.println(item.substring(beg+1,end));

I am struggling with the lastIndexOf, IndexOf and the Substring bit.

Here is a sample YouTube URL:

youtube.com/channel/UCUZHFZ9jIKrLroW8LcyJEQQ
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
rrene
  • 313
  • 1
  • 3
  • 14
  • Your code is meant for parsing YouTube URLs. Have you tried using it with the appropriate URL? – Tim Biegeleisen Jan 29 '17 at 05:45
  • The program is supposed to read the lines from the file at this URL location, http://www.dukelearntoprogram.com/course2/data/manylinks.html, and prints each URL on the page that is a link to youtube.com The program works, but I am not understading the logic behind it – rrene Jan 29 '17 at 06:07
  • This code does not make sense. IMHO it's buggy. "beg" could be easily after "end". What's the jar/package of your URLResource class? – Alex_M Jan 29 '17 at 06:15
  • Here is the jar package: http://www.dukelearntoprogram.com/course5/doc/javadoc/edu/duke/URLResource.html – rrene Jan 29 '17 at 06:19

0 Answers0