1 | We introduce two new methods: |
2 | myString.IndexOf(lookfor); |
3 | where myString and lookfor are any strings |
4 | IndexOf returns the position of a character in myString that begins a substring exactly matching lookfor: |
5 | var s = "http://www.npac.syr.edu"; |
6 | s.IndexOf("www"); // returns 7 |
7 | myString.IndexOf(lookfor, searchfrom); |
8 | where searchfrom specifies the starting position of the search (see the previous foil for an example) |
9 | myString.lastIndexOf(lookfor, lastsearchfrom); |
10 | is similar to IndexOf but starts from the end of the string |
11 | Default value of lastsearchfrom is myString.length - 1 |
12 | IndexOf and lastIndexOf return -1 if requested string is not found |