开发者

NSString: fastes way of splitting

my question is a performance question. I need to split a huge NSString into coordinates. The string has this format:

@"coordx,coordy coordx,coordy coordx,coordy (...)"

My method to parse this is:

-(NSMutableArray*) parsePath:(NSString*) pathString
{

    // first split between the coordinates
    NSArray* path = [pathString componentsSeparatedByString:@" "];

    NSMutableArray* coords = [[NSMutableArray alloc] init];

    static NSString *seperator = @",";

    NSArray *coord;
    for(NSS开发者_JS百科tring *coordString in path)
    {
        coord = [coordString componentsSeparatedByString:seperator];

        Coordinate *c = [[Coordinate alloc]init];
        c.x = [[coord objectAtIndex:0] intValue];
        c.y = [[coord objectAtIndex:1] intValue];
        [coords addObject:c];
        [c release];
    }
    return coords;
}

So, is there any way to make this faster?

Thanks!

Sebastian


Using NSScanner is probably faster.

http://developer.apple.com/iphone/library/documentation/cocoa/reference/Foundation/Classes/NSScanner_Class/Reference/Reference.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜