-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFindingLinks.java
More file actions
49 lines (28 loc) · 974 Bytes
/
FindingLinks.java
File metadata and controls
49 lines (28 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package week2;
import edu.duke.URLResource;
/**
* Created by white on 11/5/15.
*/
public class FindingLinks {
public static void main(String[] args) {
Iterable<String> words = readURL("http://www.dukelearntoprogram.com/course2/data/manylinks.html");
findLink(words);
}
public static Iterable<String> readURL(String url) {
URLResource ur = new URLResource(url);
return ur.words();
}
public static void findLink(Iterable<String> words) {
String searchWord = "youtube.com";
for (String s : words) {
int pos = s.toLowerCase().indexOf(searchWord);
if (pos != -1) {
int beg = s.lastIndexOf("\"", pos);
int end = s.indexOf("\"", pos + 1);
String w = s.substring(beg + 1, end);
System.out.format("Start: %s, End: %s \n", beg, end);
System.out.println(w);
}
}
}
}