[已解決]請問如何讓txt的內容, 顯示在array的第二欄
本帖最后由 ipmitool 于 2016-5-13 08:01 编辑請問如何讓txt的內容, 顯示在array的第二欄啊?
也就是第一欄原本為檔名, 那第二攔想要顯示為檔案裡面的內容, 要如何改呢? THANKS
打个比方你要找的错误字符为@,(如果是更复杂的需要正则), 将四个文本放到D盘1234文件夹下
1.txt
sdfasdfsadfasdadfasdfasdfasdfs!ER#$@sdfasdfsadfasdadfasdfasdfas
2.txt
sdfasdfsad@fasdadfasdfasdfasdfs!ER#$@sdfasdfsadfasdadfasdfasdfas
sdfasdfsadfasdadfasdfasdfasdfs!ER#$@sdfasdfsadfasdadfasdfasdfas
3.txt
sdfsdfsf@w32
dsfgsg@dvsfgds
advsfgfhnjt5
Sdsdfgdgdgh
dsfw43@wrgt35y45@jmryjr
4.txt
advfssfdfbg5324353@wr535t3y
ergergy43@243453
@Vadgwrgwg
VDsaf@gryjhr
代码如下:
#include <Array.au3>
#include <File.au3>
#include <MsgBoxConstants.au3>
Local $path = "d:\1234"
Local $aFileList = _FileListToArray($path, "*.txt")
If @error = 1 Then
MsgBox($MB_SYSTEMMODAL, "", "Path was invalid.")
Exit
EndIf
If @error = 4 Then
MsgBox($MB_SYSTEMMODAL, "", "No file(s) were found.")
Exit
EndIf
; Display the results returned by _FileListToArray.
_ArrayDisplay($aFileList, "$aFileList")
Local $i, $aRetArray
For $i = 1 To UBound($aFileList) - 1 Step 1
_FileReadToArray($aFileList[$i], $aRetArray, 1)
_ArrayDisplay($aRetArray, "$aRetArray")
Local $j
For $j = 1 To UBound($aRetArray) - 1
Local $start = StringInStr($aRetArray[$j], "@") ;这里是你需要查找的错误字符
If $start <> "" Then
MsgBox(0, "提示", "在文件" & $aFileList[$i] & "中,第" & $j & "行,第" & $start & "个字符" & @CRLF & "有错误的字符@")
EndIf
Next
Next 各位大大, 有人能解答嗎...拜託了... 我语文学的不怎么好,猜着楼主可能是这么个意思。。。#include <Array.au3>
#include <File.au3>
Local $path, $aFileList, $aNewList
$path = @ScriptDir
$aFileList = _FileListToArray($path, "*.txt")
If IsArray($aFileList) Then
ReDim $aNewList
For $i = 0 To UBound($aFileList) - 1 Step 1
$aNewList[$i] = $aFileList[$i]
$aNewList[$i] = FileRead($aFileList[$i])
Next
_ArrayDisplay($aNewList, "$aFileList")
EndIf
太強了吧, 這麼短就可以搞定了, 好厲害啊~~~~~~~~~~~ 請問如果要把這個array種在GUI裡面, 然後每5秒刷新一次 array, 可以辦到嗎? Thanks 回复 5# ipmitool
假設txt檔案都有好幾行, 但我只要抓最下面那一行, 顯示在array裡面, 要怎麼做啊..?
Count: 998
Count: 999
Count: 1000 参考一下, 看看可用否
_FileReadToArray 读文件内容到数组
_ArraySearch 在数组中搜索指定字符串,返回索引(用作行号) 請問如何偵測每行資料, 10分鐘沒更新狀態, 就回報msg error呢? 謝謝各位大大
页:
[1]