vb 如何查找特定两个字符所在行之间的行数

来源:百度知道 编辑:UC知道 时间:2024/06/03 21:07:14
例如
W0
.......
.....
......
......
L0
我要实现的是求出W0和L0之间的行数

新手 请高手指教
没说清楚 数据在文本文件里面 一方面是计算两者之间的行数 另外最好可以像EXCEL标序号一样 在两字符之间的每行前面标记序列号

你这些数据是在哪里的呢?在变里还是文件里?
在变量里:
aa = Mid(aa, InStr(aa, "WO"))
aa = Left(aa, InStr(aa, "LO"))

Print UBound(Split(aa, vbCrLf)) - 1

在文件里么,用line input 读出时计数就可以了
dim n as integer
dim flg1 as Boolean,flg2 as Boolean
open "wenjian" for input as #1
do while not eof(1)
line input #1,aa
n=n+1
if aa="WO" then n=0 :flg1=true
if aa="LO" then exit do : flg2=true
loop
if flg1 and flg2 then
print n
else
msgbox"没有找到""WO""或""LO"""
endif

Private Sub Command1_Click()
Dim mystr As String
Dim a As String
Dim b As String
Dim c() As String
'mystr = ....读入原始串至mystr
a = Left(mystr, InStr(1, mystr, "L0"))
b = Right(a, Len(a) - InStr(1, a, "W0"))
c = Split(b, vbCrLf)
MsgBox ("有" & UBound(c) - 1 & &quo