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