• OC6-网址分割


    //
    //  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;
    }
  • 相关阅读:
    深入理解委托、匿名方法和 Lambda 表达式
    常见SQL问题
    LeetCode题解——四数之和
    把中台说清楚
    程序员们的三高:高并发、高性能、高可用
    论文查重是怎么查的
    LeetCode题解——最长回文子串
    六百字读懂 Git(转)
    SQL中ON和WHERE的区别
    链表排序之堆排序
  • 原文地址:https://www.cnblogs.com/0515offer/p/4584142.html
Copyright © 2020-2023  润新知