Objective-C省市区用树节点来存储和读取
来源:互联网 发布:跑酷教程软件 编辑:程序博客网 时间:2024/05/21 06:44
文档请到http://wenku.baidu.com/view/234bb67b52ea551810a687ce下载
main.m
#import <Foundation/Foundation.h>#import "TreeNode.h"int main(int argc, const char * argv[]) { //准备工作 NSString * file = @"/Users/henry/Desktop/2.27/2.27/area副本.txt"; NSString * buffer = [NSString stringWithContentsOfFile:file encoding:NSUTF8StringEncoding error:nil]; NSCharacterSet * cSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789 "]; NSArray * array = [buffer componentsSeparatedByString:@"\n"]; TreeNode * country = [TreeNode treeNodeWithNode:@"China"]; //存储 for (NSString * str in array) { if (![str hasPrefix:@" "]) { NSString * s1 = [str stringByTrimmingCharactersInSet:cSet]; TreeNode * province = [TreeNode treeNodeWithNode:s1]; [country.subnode addObject:province]; } if ([str hasPrefix:@" "] && ![str hasPrefix:@" "]) { NSString * s2 = [str stringByTrimmingCharactersInSet:cSet]; TreeNode * city = [TreeNode treeNodeWithNode:s2]; TreeNode * province = [country.subnode lastObject]; [province.subnode addObject:city]; } if ([str hasPrefix:@" "]) { NSString * s3 = [str stringByTrimmingCharactersInSet:cSet]; TreeNode * district = [TreeNode treeNodeWithNode:s3]; TreeNode * procince = [country.subnode lastObject]; TreeNode * city = [procince.subnode lastObject]; [city.subnode addObject:district]; } } //输出 for (TreeNode * province in country.subnode) { if ([province.node isEqualToString:@"上海"]) { for (TreeNode * city in province.subnode) { if ([city.node isEqualToString:@"上海"]) { for (TreeNode * district in city.subnode) { NSLog(@"%@", district.node); } } } } } return 0;}TreeNode.h
#import <Foundation/Foundation.h>@interface TreeNode : NSObject@property(nonatomic, retain)NSString * node;@property(nonatomic, retain)NSMutableArray * subnode;- (id)initWithNode:(NSString *)node;+ (id)treeNodeWithNode:(NSString *)node;- (void)dealloc;@end
TreeNode.m
#import "TreeNode.h"@implementation TreeNode- (id)initWithNode:(NSString *)node { self = [super init]; if (self) { [self setNode:node]; [self setSubnode:[NSMutableArray array]]; } return self;}+ (id)treeNodeWithNode:(NSString *)node { TreeNode * treenode = [[TreeNode alloc] initWithNode:node]; return [treenode autorelease];}- (void)dealloc { [_node release]; [_subnode release]; [super dealloc];}@end<span style="color:#ff0000;"></span>
0 0
- Objective-C省市区用树节点来存储和读取
- Objective-C省市区文档用抽象树节点存储和读取(最抽象版本)
- Objective-C省市区用类代替字典存储和读取
- Objective-C 省市区 字典 封装
- Objective-C 省市区 字典 封装
- Objective--C 遍历输出对应省市区
- #Objective-C 经典字典数组排序 - 省市区
- Objective-C 省市区 三个tableView联动
- #Objective-C 经典字典数组排序 - 省市区
- 读取省市区文件,并对文件内的数据进行处理和存储
- Android 省市区的树节点控件
- Objective-C 用new来创建对象
- objective-c 读取文本文件
- C#来创建和读取XML文档
- C#来创建和读取XML文档
- C#来创建和读取XML文档
- C#来创建和读取XML文档
- C#来创建和读取XML文档
- Vim常用命令与技巧简明教程
- 如何使用笔记本电池比较好
- pat1074
- Ubuntu下安装OpenSSH Server并在客户端远程连接Ubuntu
- C语言的const和CPlusPlus的const
- Objective-C省市区用树节点来存储和读取
- 小马哥-----高仿红米note 主板为M8207 联通版15年2月新版详细拆机主板图与开机界面图
- BZOJ 3893 [Usaco2014 Dec]Cow Jog
- java程序如何获取命令行参数
- feekood的基础知识--数据分析函数
- Windows Driver Kit 8.1 Update 1
- 年终总结-致敬2014
- PCI9054 突发模式数据传输 (burst mode data transfer )
- String创建对象理解