// // HtmlManger.h // OC6-网址分割 // // Created by qianfeng on 15/6/17. // Copyright (c) 2015年 qianfeng. All rights reserved. // #import <Foundation/Foundation.h> #import "HtmlItem.h" @interface HtmlManger : NSObject { NSMutableArray *_itemList; } -(id)init; -(void)parseHtmlString:(NSString *)aString; -(void)showItemList; +(void)userInterface; -(void)addItemToItemList:(HtmlItem *)aItem; @end // // HtmlManger.m // OC6-网址分割 // // Created by qianfeng on 15/6/17. // Copyright (c) 2015年 qianfeng. All rights reserved. // #import "HtmlManger.h" @implementation HtmlManger -(id)init { if(self=[super init]) { _itemList =[NSMutableArray array]; } return self; } -(void)parseHtmlString:(NSString *)aString { NSArray *itemArray =[aString componentsSeparatedByString:@"&"]; for (NSString *itemString in itemArray) { NSArray *items =[itemString componentsSeparatedByString:@"="]; HtmlItem *item=[[HtmlItem alloc] init]; item.key=[items firstObject]; if([[items lastObject] isEqualToString:@""]) { item.value=nil; } else{ item.value=[items lastObject]; } [self addItemToItemList:item]; } } -(void)addItemToItemList:(HtmlItem *)aItem { NSInteger i; NSInteger len =[self->_itemList count]; for ( i=0;i<len;i++) { if([[[_itemList objectAtIndex:i] key] compare:aItem.key]==NSOrderedSame) { break; } } if(i!=len) { [_itemList replaceObjectAtIndex:i withObject:aItem]; } else{ [_itemList addObject:aItem]; } } -(void)showItemList { for (HtmlItem *item in _itemList) { NSLog(@"%@",item); } } +(void)userInterface { char str[100]={}; scanf("%s",str); HtmlManger *manger =[[HtmlManger alloc] init]; [manger parseHtmlString:[NSString stringWithUTF8String:str]]; [manger showItemList]; } @end
// // HtmlItem.h // OC6-网址分割 // // Created by qianfeng on 15/6/17. // Copyright (c) 2015年 qianfeng. All rights reserved. // #import <Foundation/Foundation.h> @interface HtmlItem : NSObject { NSString *_key; NSString *_value; } @property (copy,nonatomic) NSString *key; @property (copy,nonatomic) NSString *value; @end // // HtmlItem.m // OC6-网址分割 // // Created by qianfeng on 15/6/17. // Copyright (c) 2015年 qianfeng. All rights reserved. // #import "HtmlItem.h" @implementation HtmlItem -(NSString *)description { return [NSString stringWithFormat:@"%@:%@",self.key,self.value]; } @end
// // main.m // OC6-网址分割 // // Created by qianfeng on 15/6/17. // Copyright (c) 2015年 qianfeng. All rights reserved. // #import <Foundation/Foundation.h> #import "HtmlManger.h" int main(int argc, const char * argv[]) { @autoreleasepool { [HtmlManger userInterface]; //int a=23; //int const *f const =&a; } return 0; }