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 ...
随机推荐
- PL/pgSQL的 RETURN NEXT例子
从网上找到例子: 可以说,RETURN NEXT要用在循环中: 例子一: 数据准备: CREATE TABLE foo (fooid INT, foosubid INT, fooname TEXT); ...
- PostgreSQL的 initdb 源代码分析之十
继续分析, 如下这段,因为条件不成立,被跳过: /* Create transaction log symlink, if required */ ) { fprintf(stderr,"I ...
- SPOJ 1557. Can you answer these queries II 线段树
Can you answer these queries II Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 https://www.spoj.com/pr ...
- delphi Edit - TActionList
Edit TEditCut TEditCopy TEditpaste TEditSelectAll TEditUndo TEditDelete 编辑 ...
- 通过ulimit改善linux系统性能(摘自IBM)
本文介绍了 ulimit 内键指令的主要功能以及用于改善系统性能的 ulimit 用法.通过这篇文章,读者不仅能够了解 ulimit 所起的作用.而且能够学会怎样更好地通过 ulimit 限制资源的使 ...
- zend studio 函数不提醒 小黄图标 小黄标
在用 Zend Studio 编写 PHP 项目时发现调用系统函数时调试正常, 但是在编写代码时却提示函数未定义"Call to undefined function ", 在左侧 ...
- Asp.Net 之 调用分享接口
一.后台分享方式 腾讯QQ.腾讯空间.腾讯微博.新浪微博分享接口,如下: 注意:在网站对接前,请先申请注册好您的QQ登录appid.新浪登录Appkey.腾讯微博appkey. //腾讯QQ分享 ht ...
- SelectionKey理解(总结)
SelectKey注册了写事件,不在合适的时间去除掉,会一直触发写事件,因为写事件是代码触发的 client.register(selector, SelectionKey.OP_WRITE); 或者 ...
- javaweb学习总结十七(web应用组织结构、web.xml作用以及配置虚拟主机搭建网站)
一:web应用组织结构 1:web应用组成结构 2:安装web组成机构手动创建一个web应用程序目录 a:在webapps下创建目录web b:在web目录下创建html.jsp.css.js.WEB ...
- pycharm中文乱码的问题
这几天一直挺困扰的是使用pycharm之后一直对中文的乱码,即使添加了很多别人说的类似于#coding:utf-8的语句但是还是报错,让我抓狂,但是今天终于找到了解决的办法,还真的是让人很高兴啊,哈哈 ...