iLinux

自由、梦想、飞翔 --- Free Dream Soar

用户操作
[即时聊天] [发私信] [加为好友]
forlinuxID:forlinux
88184次访问,排名1072好友5人,关注者7
forlinux的文章
原创 83 篇
翻译 0 篇
转载 67 篇
评论 73 篇
只爱LINUX的公告
机遇+努力=成功
努力才会有希望...
点击这里给我发消息
最近评论
sknice:写的很好,受教了
yazhoucom:多谢,你提供的很详细
chenjunhui19840422:我也好讨厌这个功能 但不知道如何解决 谢指点
forlinux:另: 使用 Ndiswrapper时,若linux是64位的,得使用64位的windows驱动程序
bingbingw:谢谢啊,多谢了
文章分类
收藏
相册
只爱这一秒
.NET资源
.net Free soft
dotnet开源
Filehelper-Exp/Imp Data2DB
MSDN-library
Ajax Framework
jquery——The writte less,do more
prototype.js
prototype.js开发者文档
JAVA资源
java开源大全
中国IT实验室ECLIPSE专题
linux资源
202.96.64.144
ChinaUnix网友空间
Cooperative Linux(colinux)
OpenSSH For Windows
Oracle On Linux
Reactos(Wine Base)
Wine模拟器
健兔linux
成都理工大学FTP
班图LINUX
红帽Linux
长江大学FTP
鳥哥的Linux私房菜
lnux社区
linuxsir.org
linux伊甸园
linux公社
PHP资源
Apache with Open SSL
Apache软件历史版本
phpv.net
中日韩翻译
数据库相关
Oracle NetWorking FAQ
友情链接
baidu博客分站
SourceForge主页
漂在生活
闲云
存档
软件项目交易
订阅我的博客
XML聚合  FeedSky
订阅到鲜果
订阅到Google
订阅到抓虾
订阅到BlogLines
订阅到Yahoo
订阅到GouGou
订阅到飞鸽
订阅到Rojo
订阅到newsgator
订阅到netvibes

原创 stardict字典文件格式识别类 收藏

新一篇: MonoDevelop 1.0 on CentOS 5 and Fedora: Compiling and Installing | 旧一篇: UniversalQuery.net 1.0 beta is now available.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace cn.Laiyunqing
{
   
public class nStarDict
    {
       
private string idxFile;
       
private string dictFile;

       
public nStarDict(string idx, string dict)
       {
           
this.idxFile = idx;
           
this.dictFile = dict;
       }

       
public List<string> Words(string key)
       {
           List
<string> words = new List<string>();
           FileStream fsIdx 
= new FileStream(this.idxFile, FileMode.Open, FileAccess.Read);
           BinaryReader brIdx 
= new BinaryReader(fsIdx, Encoding.UTF8);
           
byte[] ch = new byte[4096];
           
byte end = (byte)'';
           
int index = 0;
           
for (index = 0; index < 4096; index++)
               ch[index] 
= (byte)'';
           index 
= 0;
           
while (true)
           {
               
try
               {
                   ch[index] 
= brIdx.ReadByte();
                   index
++;
               }
               
catch (EndOfStreamException)
               {
                   
break;
               }
               
if (ch[index - 1== end)
               {
                   
byte[] word = new byte[index - 1];
                   
for (int i = 0; i < index - 1; i++)
                   {
                       word[i] 
= ch[i];
                       ch[i] 
= 0;
                   }
                 
string queryString = Encoding.UTF8.GetString(word);
                 
if (queryString.StartsWith(key, true, System.Globalization.CultureInfo.CurrentCulture))
                 {
                     words.Add(queryString);
                 }
               }
           }
           brIdx.Close();
           fsIdx.Close();
           
return words;
       }

       
public string Result(string originalText)
       {
           
string translatedText = string.Empty;
           FileStream fsIdx 
= new FileStream(this.idxFile, FileMode.Open, FileAccess.Read);
           BinaryReader brIdx 
= new BinaryReader(fsIdx, Encoding.UTF8);
           FileStream fsDict 
= new FileStream(this.dictFile, FileMode.Open, FileAccess.Read);
           BinaryReader brDict 
= new BinaryReader(fsDict, Encoding.UTF8);
           
byte[] ch = new byte[4096];
           
byte end = (byte)'';
           
int pos, size;
           
int index = 0;
           
for (index = 0; index < 4096; index++)
               ch[index] 
= (byte)'';
           index 
= 0;
           
while (true)
           {
               
try
               {
                   ch[index] 
= brIdx.ReadByte();
                   index
++;
               }
               
catch (EndOfStreamException)
               {
                   
break;
               }
               
if (ch[index - 1== end)
               {
                   
byte[] word = new byte[index - 1];
                   
for (int i = 0; i < index - 1; i++)
                   {
                       word[i] 
= ch[i];
                       ch[i] 
= 0;
                   }
                   
string queryString = Encoding.UTF8.GetString(word);

                   index 
= 0;
                   
byte[] tmp = brIdx.ReadBytes(4);
                   pos 
= tmp[3+ (tmp[2<< 8+ (tmp[1<< 16+ (tmp[0<< 24); 
                   tmp 
= brIdx.ReadBytes(4);
                   size 
= tmp[3+ (tmp[2<< 8+ (tmp[1<< 16+ (tmp[0<< 24); 
                   
byte[] content = brDict.ReadBytes(size);
                   
string outText = Encoding.UTF8.GetString(content).Replace(" ""</br>"+ "</br>";
                   
//是查询的单词
                   if (queryString == originalText)
                   {
                       translatedText 
= outText;
                       
break;
                   }
               }
           }
           brDict.Close();
           fsDict.Close();
           brIdx.Close();
           fsIdx.Close();
           
return translatedText;
       }

    }
}
 

发表于 @ 2008年04月25日 00:28:00|评论(loading...)|编辑

新一篇: MonoDevelop 1.0 on CentOS 5 and Fedora: Compiling and Installing | 旧一篇: UniversalQuery.net 1.0 beta is now available.

评论:没有评论。

发表评论  


当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
Csdn Blog version 3.1a
Copyright © 只爱LINUX