Hey, I am trying to get the INDEX of a specific STRING in a string. I went through the API and looked at rangeOfString and whatnot but that is not what I am looking for. Here is what I need...
String s="Make money with iPhone apps";
int beginIndex=s.indexOf("iPhone");
beginIndex should equal 16.
Then from there I should be able to use substringWithRange and substring from beginIndex to beginIndex+6, to get a final string of "iPhone".
This is just an example, not exactly what I need to do but I need to find this. The reason is because I have a multi thousand character string and need to find the index of specific strings in it.
Now I know it seems like it can go out of bounds from becoming negative, but it can't because I did a length check on 'page' and it came out of length 99,419. So it should just be substringing from values INSIDE that string, but it goes OOB...any idea why?
And this isn't what am actually using this for. For some reason the index to index+30 (which was around index of 66,000) was going OOB and I couldn't figure out why, so then I did this test just to see, and that's what I found. Numbers too large?
The function NSMakeRange takes a start location and a *length* , not a start and end location. In your example, if the length is 1000, then you're trying to get a string starting at 800 with length of 850. 800 + 850 = 1650, which is out of range for string with length 1000.
Basically, the first parameter for NSMakeRange function is the index location where the range starts, and the seconds parameter is the length of the sub string.
Ah great, thanks guys. Not used to programming in this language and I keep trying to do things the way I am used too
Edit: I can't find this for the life of me. How can you set a start index? So If I want to search for another string using rangeOfString but only from a specific index. I saw NSAnchoredSearch but you never specify the index you want to start at for that...THanks
Ah great, thanks guys. Not used to programming in this language and I keep trying to do things the way I am used too
Edit: I can't find this for the life of me. How can you set a start index? So If I want to search for another string using rangeOfString but only from a specific index. I saw NSAnchoredSearch but you never specify the index you want to start at for that...THanks
Anyone on the second part? Starting from an index.