Question

I want to go through what the user input. The user is going to input some 'useless' information that i don't need right now. How would i get the slice the string so I can get the part I want.

for example:

NSString *findingText = [prefs stringForKey:userSearching]; 
NSString *substring = [string substringFromIndex:[string length] + 4]; 

But this is where i have put a specific character that i would like to search for which is !. The user has entered some information that I have used as the key. So when the user wants to find the info all they have to do is search for it and will find the special character and use that to get the NSUserDefaults. but what the User Enters doesn't always have the same length. so was wondering how I could do this.

Thanks in advance.

Was it helpful?

Solution

You can use rangeOfString function

 NSRagne range = [string rangeOfString:@"!"];

This will give you an NSRange struct that gives you the position of the ! character.

NSUInteger pos = range.location;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top