1

我尝试在 pdf 文件中找到字符串的字节位置,但它没有给我真正的价值

NSString *string2 = [NSString stringWithContentsOfFile:[[NSBundle mainBundle]  pathForResource:@"test" ofType:@"pdf"]];

    int count =0;
    int ref=0;
    int gh=0;

// array contains all the line in th epdf
 NSArray *array = [string2 componentsSeparatedByCharactersInSet:[NSCharacterSet newlineCharacterSet]];

    for ( NSString *libe in array) {

        ref++;



         count=count+[libe lengthOfBytesUsingEncoding:NSUTF8StringEncoding];

 if ([@"my string" isEqualToString:libe])
        {



            id objet1 = [array objectAtIndex:ref];

            NSString *val1=(NSString*)objet1;


            NSRange range = [val1 rangeOfString:@"mystring" options:NSBackwardsSearch];
total =count+range.location;

}

}
4

0 回答 0