OC4_电子词典
//
// 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_电子词典的更多相关文章
- 电子词典的相关子函数db.c程序
整个电子词典是分块做的:包含的Dic_Server.c,Dic_Client.c,db.c,query.c,xprtcl.c,dict.h,xprtcl.h,dict.txt(单词文件) 下面是db. ...
- C++第15周(春)项目3 - OOP版电子词典(一)
课程首页在:http://blog.csdn.net/sxhelijian/article/details/11890759.内有完整教学方案及资源链接 [项目3-OOP版电子词典](本程序中须要的相 ...
- 第14周 项目三-OOP版电子词典
做一个简单的电子词典.在文件dictionary.txt中,保存的是英汉对比的一个词典,词汇量近8000个,英文.中文释义与词性间用'\t'隔开. (1)编程序,由用户输入英文词.显示词性和中文释义. ...
- 使用Android简单实现有道电子词典
前言: 毕业设计的内容,仅仅有Java基础.没学过Android. 本着用到什么学什么.花费了10多个晚上完毕毕业设计. 当然,仅仅是简单的实线了电子词典功能,自始至终没有考虑过性能等问题. 本电子词 ...
- wxWidgets+wxSmith版电子词典
课程首页在:http://blog.csdn.net/sxhelijian/article/details/11890759,内有完整教学方案及资源链接 [项目3-OOP版电子词典](本程序须要的相关 ...
- C++第15周(春)项目3 - OOP版电子词典(二)
课程首页在:http://blog.csdn.net/sxhelijian/article/details/11890759,内有完整教学方案及资源链接 [项目3-OOP版电子词典](本程序须要的相关 ...
- OOP版电子词典
输入代码: /* * Copyright (c) 2014, 烟台大学计算机学院 * All rights reserved. * 文件名:sum123.cpp * 作 者:林海云 * 完毕日期:20 ...
- 第十四周(OOP版电子词典)
/* *copyright(c) 2015,烟台大学计算机学院 *All rights reserved. *文件名:第十四周(OOP版电子词典) *作者:王忠 *完毕日期:2015.6.10 *版本 ...
- Python实现电子词典(图形界面)
Python实现电子词典(图形界面) 终端电子词典:https://www.cnblogs.com/noonjuan/p/11341375.html 文件一览: .├── client.py├── d ...
随机推荐
- Python写的东西在CMD下打印中文
以前遇到的问题是在IDLE中可以print出中文,在cmd却是乱码. 后来想明白,IDLE中默认编码是unicode,而cmd中是ANSI,即cp963,即GBK 所以这样就能输出中文了: s = “ ...
- Codeforces Round #327 (Div. 2) E. Three States BFS
E. Three States Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/probl ...
- (字符串的模式匹配4.7.18)POJ 2406 Power Strings(求一个字符串的最小重复串)
注意,在IDE运行时,可能会因为开的数组太大而报错,这时我们可以把数组开小一点来进行调试....提交的时候把数组的大小改成1000005即可.... #include <iostream> ...
- delphi 菜单的项目是否可用
菜单的项目是否可用 TPopupMenu.OnPopup事件 把代码放在这里面判断 // ----------------------------------------------- ...
- Android 4.1源码编译找不到资源文件解决办法
我们在Android framework中修改资源文件时,在Android 4.0之前,都是直接在sourcecode/frameworks/base/core/res/res下面添加对应的资源文件, ...
- CDHtmlDialog加壳HTML5页面跳转错误解决(原)
HTML5+Native方式开发应用程序,遇到的一个问题:HTML5实现的阅读器在打开文档时,CDHtmldialog类的跳转函数报错,忽略错误程序可以正确执行. 错误代码:OnNavigateCom ...
- Windows 7中使用Eclipse 使用CDT and WinGW 开发C/C++(转载)
以前使用visual studio 2010编写C/C++,后来接触了Eclipse后,据说eclipse也可以编写C/C++,以前觉得Visual studio 2010还蛮不错的,也没有多大好奇心 ...
- PHP.10-PHP实例(一)-简单的计算器
PHP-简单的计算器 [PHP语法详解] PHP在web开发中的应用 PHP编写步骤 1.编写一个后缀名为.php文件2.上传到Web服务器的文档根目录下3.通过浏览器访问Web服务器管理下的PHP文 ...
- C语言第五节scanf函数
变量的内存分析 字节和地址 为了更好地理解变量在内存中的存储细节,先来认识一下内存中的"字节"和"地址". 内存以"字节为单位" 0x表示的 ...
- Android(java)学习笔记110:ScrollView用法
理论部分 1.ScrollView和HorizontalScrollView是为控件或者布局添加滚动条 2.上述两个控件只能有一个孩子,但是它并不是传统意义上的容器 3.上述两个控件可以互相嵌套 4. ...