找回密码
 加入
搜索
查看: 2288|回复: 4

[系统综合] 怎么获取txt文件里面的某几个字符

  [复制链接]
发表于 2011-5-20 18:13:51 | 显示全部楼层 |阅读模式
如题:我要获取udo.log里面的OnLastUserInfo - 后面的数字有多少位数
udo.log里面的内容如下
2011-05-20 18:01:09.171 -> On ConnectionEstablished
2011-05-20 18:01:09.390 -> CLocalServer::LocalLogin clientVersion 9.1.0.3,3.6.0.59
2011-05-20 18:01:09.546 -> CCommandProcessor - OnLogin
2011-05-20 18:01:10.000 -> Start IProtect Succeed.
2011-05-20 18:01:10.765 -> CCommandProcessor - OnReportAsset
2011-05-20 18:01:11.015 -> CCommandProcessor - OnGetNetbarConfig
2011-05-20 18:01:11.250 -> CFlowControlDlg::OnGetNetbarConfig
2011-05-20 18:01:11.484 -> The WWM Server IP is 192.168.0.252!
2011-05-20 18:01:11.640 -> CCommandProcessor - OnGetClientInfo
2011-05-20 18:01:11.875 -> AutoCheckIn
2011-05-20 18:01:12.125 -> OnLastUserInfo - 0215674275
2011-05-20 18:01:11.531 -> Start IProtect Succeed.
发表于 2011-5-20 18:33:06 | 显示全部楼层
$file = FileOpen("udo.log", 0)

; 检查打开的文件是否可读
If $file = -1 Then
        MsgBox(0, "错误", "不能打开文件.")
        Exit
EndIf

; 每次读取一行文本,直到文件结束.
While 1
        $line = FileReadLine($file)
        If @error = -1 Then ExitLoop
        If StringInStr($line, "OnLastUserInfo") <> 0 Then
                $text = StringStripWS($line, 8)
                $text = StringSplit($text, "-")
                $result = StringLen($text[$text[0]])
                MsgBox(0, "字符长度:", $result)
        EndIf
Wend

FileClose($file)
发表于 2011-5-20 18:42:08 | 显示全部楼层
$Pass = StringRegExp($line,'OnLastUserInfo - (\d+)',3)
发表于 2011-5-20 18:53:51 | 显示全部楼层
(?<=-\s)\d+
发表于 2011-5-20 18:55:29 | 显示全部楼层
$file = FileOpen("udo.log")
$str = StringRegExp(FileRead($file), '(?<=OnLastUserInfo\s-\s)\d+', 3)
FileClose($file)

MsgBox(0,"",$str[0])
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-11-14 14:48 , Processed in 0.073459 second(s), 23 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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