I have this NSString
Asia/Tokyo I want to get only "Tokyo" by removing "Asia/" I know it will get to work by searching for the position of "/" but how do i do that? pls help
I have this NSString
Asia/Tokyo I want to get only "Tokyo" by removing "Asia/" I know it will get to work by searching for the position of "/" but how do i do that? pls help
To get the location of a substring in a string :
[@"Asia/Tokyo" rangeOfString:@"/"].location rangeOfString:options:range if you want to find other instances, or search backwards, or other things covered by the options.Just split the string with componentsSeparatedByString:@"/" This'll return an array, and you just grab the second element.
[input componentsSeparatedByString:@"/"][1] is a perfectly good solution.substringFromIndex: to get the needed substring after getting the range of the delimiter.You can use rangeOfString to give you the location of string. I would also run the range through an if statement looking for NSNotFound just in case the string you are looking for isn't found.