找回密码
 加入
搜索
查看: 5364|回复: 9

[AU3基础] 【已解决】 txt文本读取问题,请教。。谢谢

  [复制链接]
发表于 2015-6-20 15:23:42 | 显示全部楼层 |阅读模式
本帖最后由 pingfan5888 于 2015-7-11 18:30 编辑

想要弄个词组构词查询。txt读取请教 大大。。谢谢。。
条件:

词组,大于等于,两个字。小于20个字。
两个字,取每个字的两个编码组成。
三个,取前两个字,第一个编码,最后一个字,前两个编码。

三个以上,取前三个字,第一个编码,最后一个字,第一个编码。组成。
如:
输入:哀唉        显示 wkky
输入:哀唉埃      显示 wkty
输入:哀唉埃哀    显示 wktw


是用 数组 吗,还是用 正则表达式 来从 去一简.txt  完成检测。读取编码。
如何修改,

特请教各位老大。。万分感谢。
#include<array.au3>
#include <File.au3>


#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 449, 192, 114)
$Input1 = GUICtrlCreateInput("", 72, 24, 121, 21)
$Input2 = GUICtrlCreateInput("", 72, 56, 121, 21)
$Button1 = GUICtrlCreateButton("查询", 72, 96, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit


                Case $Button1
                _ld()
        EndSwitch
WEnd


GUISetState()


Func _ld()
        ; _GUICtrlListView_DeleteAllItems($ListView1)
        Local $str, $i, $dt, $aArray1, $aArray2
        Global $bm
        Global $dt
        $ct = GUICtrlRead($Input1)
        _FileReadToArray(@ScriptDir & "\去一简.txt", $aArray1)

        

        For $i = 1 To UBound($aArray1) - 1
                $str = StringSplit($aArray1[$i], "        ")
                $wz = $str[1]
                
                $bm = $str[2]

                

                $dt = $wz & '|' & $bm
                If $ct = $wz Then
                        ;MsgBox(0, '记录:' & $wz, $dt)
                        GUICtrlSetData($Input2, $bm)
                Else
                EndIf

                ; GUICtrlCreateListViewItem($dt, $ListView1)
                
                
        Next
        
        
        
EndFunc   ;==>_ld
去一简.txt
哎        kh
哀        wk
唉        ky
埃        ty
挨        jy
欸        yr
溾        vx
锿        qw
啀        kg
捱        jg
皑        xc
凒        dc
嵦        cc
溰        vc
嘊        kc
格式:汉字 + tab键 + 编码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
发表于 2015-6-21 18:47:14 | 显示全部楼层
完全没有看明白你在说什么。
 楼主| 发表于 2015-6-21 21:46:54 | 显示全部楼层
本帖最后由 pingfan5888 于 2015-6-21 21:53 编辑
完全没有看明白你在说什么。
luren666 发表于 2015-6-21 18:47



抱歉,编辑时没有注意到

如:
输入:哀唉        显示 wkky
输入:哀唉埃      显示 wkty
输入:哀唉埃哀    显示 wktw


是用 数组 吗,还是用 正则表达式 来从 “去一简.txt ” 完成检测。读取编码。
如何修改,请教了,谢谢。。
发表于 2015-7-8 08:04:09 | 显示全部楼层
这个工程量很大,应该会用到正则一类的!
发表于 2015-7-9 23:11:13 | 显示全部楼层
#include<array.au3>
#include <File.au3>


#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 623, 449, 192, 114)
$Input1 = GUICtrlCreateInput("啊嗄哀", 72, 24, 121, 21)
$Input2 = GUICtrlCreateInput("", 72, 56, 121, 21)
$Button1 = GUICtrlCreateButton("查询", 72, 96, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
_ld()  ;;;载入码表

While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
                Case $GUI_EVENT_CLOSE
                        Exit
                Case $Button1
                                        $code = query(GUICtrlRead($Input1))
                                        If $code Then
                                                GUICtrlSetData($Input2,$code)
                                        Else
                                                GUICtrlSetData($Input2,"未找到")
                                        EndIf
        EndSwitch
WEnd


GUISetState()


Func _ld()
        Local $aArray1
                If Not _FileReadToArray(@ScriptDir & "\去一简.txt", $aArray1) Then
                        MsgBox(4096, "错误", "读取文件失败  error:" & @error)
                        Exit
                EndIf
                Global $aArray2[$aArray1[0] + 1][2]   ;;;定义一个全局二维数组用以存放编码文件
                $aArray2[0][0] = $aArray1[0]   ;;总行数
                
        For $i = 1 To $aArray1[0]
                $str = StringSplit($aArray1[$i], "        ")
                                If $str[0] = 2 Then
                                        $aArray2[$i][0] = $str[1]        ;;;第一维存字
                                        $aArray2[$i][1] = $str[2]        ;;;第二维存编码
                                EndIf
        Next
EndFunc



Func query($word)
        If StringLen($word) < 2 Or StringLen($word) > 20 Then   ;;不足两字
                Return "单词太短或太长" 
        ElseIf StringLen($word) = 2 Then  ;;2字
                $one = StringLeft($word,1)    ;;第一个字
                $two = StringRight($word,1)   ;;第二个字
                Local $oneCode = "" ,$twoCode = ""
                For $i = 1 To $aArray2[0][0]
                        If $one = $aArray2[$i][0] Then $oneCode = $aArray2[$i][1]  ;;第一个字的编码
                        If $two = $aArray2[$i][0] Then $twoCode = $aArray2[$i][1]  ;;第二个字的编码
;~                         If $oneCode And $twoCode Then ExitLoop    ;;;如果找到了就退出循环,避免一直循环到尾部
                Next
                If $oneCode <> "" And $twoCode <> "" Then   ;;如果查到了就返回编码,未查到返回0
                        Return $oneCode & $twoCode
                Else
                        Return 0
                EndIf
        Else  ;;;3字和3字以上
                $one = StringLeft($word,1)  ;;第一个字
                $two = StringMid($word,2,1)  ;;;第二个字
                $three = StringRight($word,1) ;;;最后一个字
                Local $oneCode = "" ,$twoCode = "",$threeCode = "" 
                For $i = 1 To $aArray2[0][0]
                        If $one = $aArray2[$i][0] Then $oneCode = StringLeft($aArray2[$i][1],1)   ;;第一个字的编码
                        If $two = $aArray2[$i][0] Then $twoCode = StringLeft($aArray2[$i][1],1)   ;;第二个字的编码
                        If $three = $aArray2[$i][0] Then $threeCode = $aArray2[$i][1]                          ;;第三个字的编码
                        If $oneCode And $twoCode And $threeCode Then ExitLoop   ;;;如果找到了就退出循环,避免一直循环到尾部
                Next
                If $oneCode <> "" And $twoCode <> "" And $threeCode <> "" Then ;;如果查到了就返回编码,未查到返回0
                        Return $oneCode & $twoCode & $threeCode
                Else
                        Return 0
                EndIf
        EndIf
EndFunc
几千行的文本文件处理起来还是没问题的。
发表于 2015-7-9 23:14:06 | 显示全部楼层
抱歉,刚才没有注意看您的要求,三个字以上的都按照三个字来处理了,您自己改一下吧,也算给您自己留个作业练习一下。
发表于 2015-7-10 22:50:54 | 显示全部楼层
有点高深的问题。。
发表于 2015-7-11 16:55:14 | 显示全部楼层
不错的,例子,很好
 楼主| 发表于 2015-7-11 18:28:31 | 显示全部楼层
几千行的文本文件处理起来还是没问题的。
luren666 发表于 2015-7-9 23:11


非常感谢啊,自己尝试写了,不成功,能力不够。

网站打开有点慢,没注意,现在才看到。。万分感谢。弄这个的目的,是因为自己平时经常要添加,修改五笔词组,不方便,就想弄一个。。
 楼主| 发表于 2015-7-11 18:56:05 | 显示全部楼层
抱歉,刚才没有注意看您的要求,三个字以上的都按照三个字来处理了,您自己改一下吧,也算给您自己留个作业 ...
luren666 发表于 2015-7-9 23:14


好的,谢谢了啊。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-9-28 18:18 , Processed in 0.110285 second(s), 24 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表