//
// MyDictionary.h
// OC4_电子词典
//
// Created by zhangxueming on 15/6/15.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <Foundation/Foundation.h> #define FilePath @"/Users/zhangxueming/Desktop/ios1509/Day16_类的复合设计/dict.txt" @interface MyDictionary : NSObject
{
NSMutableDictionary *_mulDict;
} - (id)initWithFile:(NSString *)path; + (void)userInterface; @end
//
// MyDictionary.m
// OC4_电子词典
//
// Created by zhangxueming on 15/6/15.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import "MyDictionary.h" @interface MyDictionary () - (BOOL)parseFileContent:(NSString *)path; @end @implementation MyDictionary - (id)initWithFile:(NSString *)path
{
self = [super init];
if (self) {
_mulDict = [NSMutableDictionary dictionary];
[self parseFileContent:path];
}
return self;
} - (BOOL)parseFileContent:(NSString *)path
{
//读取字典文件
NSString *fileContent = [NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:nil];
//判断是否读取成功
if(!fileContent)
{
return NO;
}
//解析
NSArray *contentItems = [fileContent componentsSeparatedByString:@"\n"];
NSInteger len = [contentItems count];
for (NSInteger i=; i<len; i+=) {
if ([[contentItems objectAtIndex:i] isEqualToString:@""]) {
continue;
}
NSString *key = [[contentItems objectAtIndex:i] substringFromIndex:];
NSString *value = [[[contentItems objectAtIndex:i+] substringFromIndex:] stringByReplacingOccurrencesOfString:@"@" withString:@"\n"];
[_mulDict setObject:value forKey:key];
}
return YES;
} + (void)userInterface
{
MyDictionary *dict = [[MyDictionary alloc] initWithFile:FilePath];
NSLog(@"欢迎使用电子词典");
char str[]={};
while (YES) {
NSLog(@"请输入要查找的单词:");
scanf("%s", str);
NSLog(@"翻译:%@",[dict->_mulDict objectForKey:[NSString stringWithUTF8String:str]]);
}
} @end
//
// main.m
// OC4_电子词典
//
// Created by zhangxueming on 15/6/15.
// Copyright (c) 2015年 zhangxueming. All rights reserved.
// #import <Foundation/Foundation.h>
#import "MyDictionary.h" int main(int argc, const char * argv[]) {
@autoreleasepool {
[MyDictionary userInterface];
}
return ;
}

OC4_电子词典的更多相关文章

  1. 电子词典的相关子函数db.c程序

    整个电子词典是分块做的:包含的Dic_Server.c,Dic_Client.c,db.c,query.c,xprtcl.c,dict.h,xprtcl.h,dict.txt(单词文件) 下面是db. ...

  2. C++第15周(春)项目3 - OOP版电子词典(一)

    课程首页在:http://blog.csdn.net/sxhelijian/article/details/11890759.内有完整教学方案及资源链接 [项目3-OOP版电子词典](本程序中须要的相 ...

  3. 第14周 项目三-OOP版电子词典

    做一个简单的电子词典.在文件dictionary.txt中,保存的是英汉对比的一个词典,词汇量近8000个,英文.中文释义与词性间用'\t'隔开. (1)编程序,由用户输入英文词.显示词性和中文释义. ...

  4. 使用Android简单实现有道电子词典

    前言: 毕业设计的内容,仅仅有Java基础.没学过Android. 本着用到什么学什么.花费了10多个晚上完毕毕业设计. 当然,仅仅是简单的实线了电子词典功能,自始至终没有考虑过性能等问题. 本电子词 ...

  5. wxWidgets+wxSmith版电子词典

    课程首页在:http://blog.csdn.net/sxhelijian/article/details/11890759,内有完整教学方案及资源链接 [项目3-OOP版电子词典](本程序须要的相关 ...

  6. C++第15周(春)项目3 - OOP版电子词典(二)

    课程首页在:http://blog.csdn.net/sxhelijian/article/details/11890759,内有完整教学方案及资源链接 [项目3-OOP版电子词典](本程序须要的相关 ...

  7. OOP版电子词典

    输入代码: /* * Copyright (c) 2014, 烟台大学计算机学院 * All rights reserved. * 文件名:sum123.cpp * 作 者:林海云 * 完毕日期:20 ...

  8. 第十四周(OOP版电子词典)

    /* *copyright(c) 2015,烟台大学计算机学院 *All rights reserved. *文件名:第十四周(OOP版电子词典) *作者:王忠 *完毕日期:2015.6.10 *版本 ...

  9. Python实现电子词典(图形界面)

    Python实现电子词典(图形界面) 终端电子词典:https://www.cnblogs.com/noonjuan/p/11341375.html 文件一览: .├── client.py├── d ...

随机推荐

  1. Actions 动作集

    --> 移动鼠标到指定位置(先触发onMouseOver动作)        Actions action = new Actions(driver);        WebElement th ...

  2. UVa10562 Undraw the Trees

      注意点: 空树情况处理. >= && buf[r+][i-]=='-') i--; #include<cstdio> #include<cstring> ...

  3. 微信公众平台Token验证失败的解决办法

    微信公众平台Token验证失败的解决办法 1.可查看url和token是否正确 2.查看服务器端口是否为80端口 3.你可以通过记录log日志来判断是否接受到微信提交过来的信息 1.$fp=fopen ...

  4. Js Pattern - Self Define Function

    This pattern is useful when your function has some initial preparatory work to do andit needs to do ...

  5. CDOJ 483 Data Structure Problem DFS

    Data Structure Problem Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.uestc.edu.cn/#/proble ...

  6. Hanoi Tower问题分析

    前言 回家休息第3天了,状态一直不是太好,主要是要补牙,检查身体,见同学见亲戚,心里又着急校招,难得能腾出时间来好好思考,这里也是看<cracking the coding interview& ...

  7. Plus One @LeetCode

    import java.util.Arrays; /** * Plus One * * Given a number represented as an array of digits, plus o ...

  8. C语言面试题大汇总

    static有什么用途?(请至少说明两种)1.限制变量的作用域2.设置变量的存储域7. 引用与指针有什么差别?1) 引用必须被初始化,指针不必.2) 引用初始化以后不能被改变,指针能够改变所指的对象. ...

  9. zookeeper-3.4.6安装

    下载zookeeper包并解压 配置.在conf文件夹中将zoo_sample.cfg复制一份为zoo.cfg 修改zoo.cfg 在/home/admln/zookeeper中新建一个文件myid( ...

  10. Android 高级UI设计笔记05:使用TextView实现跑马灯的效果

    1. 使用TextView属性实现跑马灯的效果: (1). 新建一个Android工程,命名为"MarqueeTextViewDemo",如下: (2). 来到activity_m ...