如何使用NSString结构体

      // 处理这个纪录

        

        A_Record record_one;

        

        record_one  = [self get_one_from_html: str_one_record ];


函数:

-(A_Record )get_one_from_html:(NSString *)one_record

{

    A_Record record_one;

    NSString *record=@"";

    record = [one_record substringFromIndex:2];

    

    if([record rangeOfString:@"]," options:NSCaseInsensitiveSearch].location != NSNotFound)

    {

        if(((one_record.length - 4)>0) || ((one_record.length - 4)==0))

        {

           record = [record substringToIndex:one_record.length - 4];

        }

        else

        {

           record = @"";

        }

    }

    else if([record rangeOfString:@"]" options:NSCaseInsensitiveSearch].location != NSNotFound)

    {

        if(((record.length - 2)>0) || ((record.length - 2)==0))

        {

            record = [record substringToIndex:record.length - 2];

        }

        else

        {

            record = @"";

        }

    }

    

    NSString *find_start = @",";

    NSRange foundRange_start = [record rangeOfString:find_start options:NSCaseInsensitiveSearch];

    NSString *str_rest = @"";

    int pos_start = 0;

    NSString *str1 = @"";

    NSString *str2 = @"";

    NSString *str3 = @"";

    

    int i_count =0;

    

    while (foundRange_start.location != NSNotFound)

    {

        i_count++;

        pos_start = foundRange_start.location + foundRange_start.length + 1;

        if(1 == i_count)

        {

            if((pos_start-3)>=0)

            {

               str1 = [record substringToIndex:pos_start-3];

            }

            else

            {

                str1 = @"";

            }

        }

        else if(2==i_count)

        {

            if((pos_start-3)>=0)

            {

                str2 = [record substringToIndex:pos_start-3];

            }

            else

            {

                str2 = @"";

            }

        }

        // 开始下一个

        str_rest = [record substringFromIndex:pos_start];

        record =str_rest;

        foundRange_start = [record rangeOfString:find_start options:NSCaseInsensitiveSearch];

    }

    

    int pos_location_last = record.length-3;

    

    if(pos_location_last>0)

    {

        str3 = [record substringToIndex:pos_location_last];

    }

    else if(pos_location_last<=0)

    {

        str3 = @"";

    }

    

    

    if(str3.length == 0)

    {

        str3 = @"NULL";

    }

    else

    {

        str3= [str3 stringByReplacingOccurrencesOfString:@"|" withString:@"!"];

    }

    

    if(str2.length == 0)

    {

        str2 = str3;

    }

    

    record_one.id =str1;

    record_one.name =str2;

    record_one.number =str3;    

    return record_one;

}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值