以文本方式查看主题 - Foxtable(狐表) (http://foxtable.com/bbs/index.asp) -- 专家坐堂 (http://foxtable.com/bbs/list.asp?boardid=2) ---- [求助]怎样提取下面一段文字?读取TXT文本qq聊天记录 (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=160353) |
-- 作者:zto001 -- 发布时间:2021/1/30 9:44:00 -- [求助]怎样提取下面一段文字?读取TXT文本qq聊天记录 下面这段文字,我需要把时间、类型、接收者、发送者、群号、内容分列出来,怎么分比较好? 时间=2021-1-30 09:41:57 类型=群 接收者=2722838195 发送者=389438458 群号=391491058 内容=运单号
店铺
问题件类型
问题件原因【换行】75408905
tb3812_2011
地址不详/错误
已联系客户确认地址为:(湖南省邵阳市大祥区雨溪桥。)。 奇怪,怎么发表后内容分列了 [此贴子已经被作者于2022/2/22 13:20:16编辑过]
|
-- 作者:有点蓝 -- 发布时间:2021/1/30 10:00:00 -- 参考:http://www.foxtable.com/webhelp/topics/0245.htm 根据空格拆分,在根据等号拆分,可以看看:http://www.foxtable.com/webhelp/topics/2629.htm
|
-- 作者:zto001 -- 发布时间:2021/1/30 10:20:00 -- 这个我知道,我是想说有没有正则表达式或则其他简便的方法。这样写下来感觉好亢杂 Dim dlg As New OpenFileDialog dlg.MultiSelect = True If dlg.ShowDialog = DialogResult.OK Then Dim strs As String = FileSys.ReadAllText(dlg.FileName,Encoding.Default) Dim Values() As String Values = strs.split( vbcrlf ) For Index As Integer = 0 To Values.Length - 1 Output.Show(Values(Index)) Dim Values0() As String Dim shu As Integer Values0 = Values(Index).split("=") For Index0 As Integer = 0 To Values0.Length - 1 \'Output.Show(Values0(Index0)) shu =Index0 Next \' Dim 行 As Row=Tables("消息记录").AddNew() 行("时间")=Values0(1).Replace(" 类型","") 行("类型")=Values0(2).Replace(" 接收者","") 行("接收者")=Values0(3).Replace(" 发送者","") If Values0(2).Replace(" 接收者","")="好友" Then 行("发送者")=Values0(4).Replace(" 内容","") 行("内容")=Values0(5) Else 行("发送者")=Values0(4).Replace(" 群号","") 行("群号")=Values0(5).Replace(" 内容","") If shu >=6 Then 行("内容")=Values0(6) End If End If Next End If |
-- 作者:zto001 -- 发布时间:2021/1/30 10:23:00 -- 我上面这段代码执行的时候老是出现这样的错误,我想可能是TXT文件在不停的新增导致的。有没有好的解决方案? 版本:2020.5.29.8 × 代码执行出错,错误信息: system.IndexOutOfRangeException:索引超出了数组界限。在UserCode.Test0 确定 |
-- 作者:有点蓝 -- 发布时间:2021/1/30 10:41:00 -- 和这个没有关系。FileSys.ReadAllText是一次性读入内存的,文件新增对已经读入的数据不可能有影响。 Dim 行 As Row=Tables("消息记录").AddNew() if Values0.length = 7 then 行("时间")=Values0(1).Replace(" 类型","") 行("类型")=Values0(2).Replace(" 接收者","") 行("接收者")=Values0(3).Replace(" 发送者","") If Values0(2).Replace(" 接收者","")="好友" Then 行("发送者")=Values0(4).Replace(" 内容","") 行("内容")=Values0(5) Else 行("发送者")=Values0(4).Replace(" 群号","") 行("群号")=Values0(5).Replace(" 内容","") If shu >=6 Then 行("内容")=Values0(6) End If End If end if 或者逐个判断 Dim 行 As Row=Tables("消息记录").AddNew() if Values0.length >1 then 行("时间")=Values0(1).Replace(" 类型","") if Values0.length >2 then 行("类型")=Values0(2).Replace(" 接收者","") if Values0.length >3 then 行("接收者")=Values0(3).Replace(" 发送者","") |
-- 作者:zto001 -- 发布时间:2021/1/30 12:16:00 -- 我知道了,是最后一行是空白行,所以解析不了,解析到倒数第二个就行了 \'Dim dlg As New OpenFileDialog \'dlg.MultiSelect = True \'If dlg.ShowDialog = DialogResult.OK Then Dim strs As String = FileSys.ReadAllText("D:\\软件\\记录输出.txt",Encoding.Default) Dim Values() As String Values = strs.split( vbcrlf ) For Index As Integer = 0 To Values.Length - 2 Dim Values0() As String If Values.length >Index Then Values0 = Values(Index).split("=") Dim 行 As Row=Tables("聊天记录").AddNew() If Values0.length >1 Then 行("时间")=Values0(1).Replace(" 类型","") If Values0.length >2 Then 行("类型")=Values0(2).Replace(" 接收者","") If Values0.length >3 Then 行("接收者")=Values0(3).Replace(" 发送者","") If Values0(2)="好友 接收者" Then If Values0.length >4 Then 行("发送者")=Values0(4).Replace(" 内容","") If Values0.length >5 Then 行("内容")=Values0(5) Else If Values0.length >4 Then 行("发送者")=Values0(4).Replace(" 群号","") If Values0.length >5 Then 行("群号")=Values0(5).Replace(" 内容","") If Values0.length >6 Then 行("内容")=Values0(6) End If End If Next |