//
// 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. 安装Loopback网卡/回环网卡

    $CurrentPath = $MyInvocation.MyCommand.Path.substring(0,$MyInvocation.MyCommand.Path.LastIndexOf('\' ...

  2. StructureMap 学习笔记(1)

    前言 一个偶然的机会接触到了StructureMap,当时客户要求让程序具有较好的测试性,自然而然就想到了IOC 容器. 之后就去Google了一下, 不经意间在StackOverFlow找到一篇帖子 ...

  3. Codeforces Round #185 (Div. 2) C. The Closest Pair 构造

    C. The Closest Pair Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/312/p ...

  4. pjsip视频通信开发(上层应用)之数字键盘的制作

    在pjsip视频通信开发(上层应用)之EditText重写中我制作了一个显示输入内容的EditText,这里将制作一个数字键盘,其实跟计算器一样,最多的就是用TableLayout来实现,内部通过权重 ...

  5. [置顶] 异步加载图片,使用LruCache和SD卡或手机缓存,效果非常的流畅

    转载请注明出处http://blog.csdn.net/xiaanming/article/details/9825113 异步加载图片的例子,网上也比较多,大部分用了HashMap<Strin ...

  6. [ES6] 16. Object Enhancements

    Define object: var color = "blue"; var speed = 120; var car = {color, speed}; console.log( ...

  7. Android 滑动效果基础篇(三)—— Gallery仿图像集浏览

    Android系统自带一个Gallery浏览图片的应用,通过手指拖动时能够非常流畅的显示图片,用户交互和体验都很好. 本示例就是通过Gallery和自定义的View,模仿实现一个仿Gallery图像集 ...

  8. C#多线程交替赋值取值

    static AutoResetEvent auto=new AutoResetEvent(false); ; ; static void Main() { Thread th1 = new Thre ...

  9. Helpers\TableBuilder

    Helpers\TableBuilder Table builder helper is a class that would help you to create tables in MySQL ( ...

  10. Neo4查询语言Cypher3.0.7在antlr4下的文法(原创分享)

    本人网上找了很久都没有一个比较好的cypher文法,于是花了一段时间研究cypher和编写基于antlr4下的cypher文法. 希望对想用做cypher相关工具的朋友有一点用,欢迎交流. 珍重声明: ...