本文主要是介绍如何使用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;
}
这篇关于如何使用NSString结构体的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!