2

When I have pf:/Abc/def/, how can I get the /Abc/def/?

With Python, I can use

string = 'pf:/Abc/def/'
string.split(':')[1]

or even

string[3:]

What's the equivalent function in Objective-C?

1 Answer 1

6
NSString *string = [NSString stringWithFormat:@"pf:/Abc/def/"];
NSArray *components = [string componentsSeparatedByString: @":"];
NSString *string2 = (NSString*) [components objectAtIndex:1];

Reference: http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html#//apple_ref/occ/instm/NSString/componentsSeparatedByString:

componentsSeparatedByString will return an NSArray. You grab the object at a certain index, and type cast it to NSString when storing it into another variable.

Sign up to request clarification or add additional context in comments.

1 Comment

I get 'invalid initializer' at line 3 (NSString string2 = ...)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.