标题:TXT内容段查找思路应该如何写代码???
只看楼主
ffcb
Rank: 1
等 级:新手上路
帖 子:38
专家分:0
注 册:2010-1-23
结帖率:0
已结贴  问题点数:20 回复次数:11 
TXT内容段查找思路应该如何写代码???
在TXT文本中有
*1.A:123,*2.B:234,*3.C:345,...以此类推
希望能提取各段的字符作为表格的输入内容
应该如何操作???
提取后的格式如下:
1.A|2.B|3.C|...
123
搜索更多相关主题的帖子: 代码 思路 TXT 
2010-02-04 11:28
ffcb
Rank: 1
等 级:新手上路
帖 子:38
专家分:0
注 册:2010-1-23
得分:0 
格式如下:
1.A|2.B|3.C|...
123|234|345|...
2010-02-04 11:29
ffcb
Rank: 1
等 级:新手上路
帖 子:38
专家分:0
注 册:2010-1-23
得分:0 
想要以“*”为开头到“:”为小标开头;
“:”开头“,”为内容部分。
请问代码应该怎么写?
2010-02-04 11:30
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4912
专家分:29900
注 册:2008-10-15
得分:6 
split() 函数

第一次以   , 为分隔符进行分解,分出各个段来.

然后第二次以 : 为分隔符分成二段, 第二段为 你所需要的内容.


注意,split() 函数返回的是一个动态\下标为从0 开始的字符串数组.


授人于鱼,不如授人于渔
早已停用QQ了
2010-02-04 15:25
ffcb
Rank: 1
等 级:新手上路
帖 子:38
专家分:0
注 册:2010-1-23
得分:0 
风,按照你的提示我写了代码,可是提示我红色字段错误
请问错在哪里??
Dim hintNO As Integer

Dim i As String
Dim j As String
Dim x As String
Dim y As Integer
Dim z1() As String
Dim z2() As String
Private Sub addhint_Click()
    hintNO = hintNO + 1
    Load hint(hintNO)
    hint(hintNO).Caption = "信息" & hintNO
    Form1.Show

End Sub

Private Sub blue_Click()
    red.Checked = False
    green.Checked = False
    blue.Checked = True
    defaultcolor.Checked = False
    Form4.BackColor = vbBlue
End Sub

Private Sub defaultcolor_Click()
    red.Checked = False
    green.Checked = False
    blue.Checked = False
    defaultcolor.Checked = True
    Form4.BackColor = &H8000000F
End Sub
Private Sub docfile_Click()

    txtfile.Checked = False
    jpgfile.Checked = False
    exefile.Checked = False
    pdhfile.Checked = False
    docfile.Checked = True
    elxfile.Checked = False
    File1.Pattern = "*.doc"
End Sub


Private Sub ELXfile_Click()
    txtfile.Checked = False
    jpgfile.Checked = False
    exefile.Checked = False
    pdhfile.Checked = False
    docfile.Checked = False
    elxfile.Checked = True
    File1.Pattern = "*.elx"
End Sub

Private Sub EXEfile_Click()
    txtfile.Checked = False
    jpgfile.Checked = False
    exefile.Checked = True
    pdhfile.Checked = False
    docfile.Checked = False
    elxfile.Checked = False
    File1.Pattern = "*.exe"
End Sub

Private Sub Form_Load()
    Drive1.Drive = "d:"
    Dir1.Path = "D:\ttt\个人文件夹\收件箱"
    red.Checked = False
    green.Checked = False
    blue.Checked = False
    defaultcolor.Checked = False
   
    txtfile.Checked = False
    jpgfile.Checked = False
    exefile.Checked = False
    pdhfile.Checked = False
    docfile.Checked = False
    elxfile.Checked = False
    File1.Pattern = "*.*"
   
   
   
End Sub

Private Sub green_Click()
    red.Checked = False
    green.Checked = True
    blue.Checked = False
    defaultcolor.Checked = False
    Form4.BackColor = vbGreen
End Sub

Private Sub JPGfile_Click()
    txtfile.Checked = False
    jpgfile.Checked = True
    exefile.Checked = False
    pdhfile.Checked = False
    docfile.Checked = False
    elxfile.Checked = False
    File1.Pattern = "*.jpg"
End Sub

Private Sub PDHfile_Click()
    txtfile.Checked = False
    jpgfile.Checked = False
    exefile.Checked = False
    pdhfile.Checked = True
    docfile.Checked = False
    elxfile.Checked = False
    File1.Pattern = "*.pdh"
End Sub

Private Sub red_Click()
    red.Checked = True
    green.Checked = False
    blue.Checked = False
    defaultcolor.Checked = False
    Form4.BackColor = vbRed
End Sub

Private Sub removehint_Click()
If hintNO <= 0 Then
Exit Sub
Else
    Unload hint(hintNO)
    hintNO = hintNO - 1
End If

End Sub

Private Sub Dir1_Change()
    File1.Path = Dir1.Path
End Sub

Private Sub Drive1_Change()
    Dir1.Path = Drive1.Drive
End Sub

Private Sub File1_Click()

    i = File1.List(File1.ListIndex)
   
If UCase(Right(i, 4)) = ".TXT" Then

    Open (File1.Path & "\" & i) For Input As #1
    Do While Not EOF(1)
    Line Input #1, j
    j = Text & j & vbCrLf
    Loop
   
   
    Close #1
    j = Replace(j, ".a", ".speed")
    j = Replace(j, ".b", ".high")
    j = Replace(j, ".c", ".weigth")
    j = Replace(j, "*", vbCrLf & "")
End If
    RichTextBox1.Text = j
   
    z1() = Split(j, ",")
    z2() = Split(z1(), ":")
   
    MSFlexGrid2.TextMatrix() = z2()
End Sub





Private Sub TXTfile_Click()
    txtfile.Checked = True
    jpgfile.Checked = False
    exefile.Checked = False
    pdhfile.Checked = False
    docfile.Checked = False
    elxfile.Checked = False
    File1.Pattern = "*.txt"
For y = 0 To File1.ListCount - 1
    x = File1.List(y)


If UCase(Right(x, 4)) = ".TXT" Then

    File1.Pattern = x

End If
Next y
End Sub


2010-02-05 17:36
风吹过b
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:贵宾
威 望:364
帖 子:4912
专家分:29900
注 册:2008-10-15
得分:0 

'需要使用循环将每段进行分别处理
for k=0 to ubound(z1)
    z2() = Split(z1(k), ":")
   
    MSFlexGrid2.TextMatrix() = z2()        '这句我不会改,要改成每次处理一段
next k

授人于鱼,不如授人于渔
早已停用QQ了
2010-02-06 10:31
bczgvip
Rank: 14Rank: 14Rank: 14Rank: 14
等 级:贵宾
威 望:66
帖 子:1310
专家分:5312
注 册:2009-2-26
得分:6 
    z2() = Split(z1(), ":")
    ReDim Preserve z2(0 to 1)
2010-02-06 10:48
ffcb
Rank: 1
等 级:新手上路
帖 子:38
专家分:0
注 册:2010-1-23
得分:0 
不好意思,UBOUND(Z1)这个函数是啥意思???
2010-02-06 11:12
ffcb
Rank: 1
等 级:新手上路
帖 子:38
专家分:0
注 册:2010-1-23
得分:0 
ReDim Preserve z2(0 to 1)
又是啥意思?重新定义Z2???
2010-02-06 11:13
ffcb
Rank: 1
等 级:新手上路
帖 子:38
专家分:0
注 册:2010-1-23
得分:0 
ReDim Preserve z2(0 to 1)
又是啥意思?重新定义Z2???
2010-02-06 11:35



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-297235-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.012610 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved