求助:字符串截取

qq_29298783 2018-04-08 10:24:59
bbXyJoFm lz7YFB6u

iqAIZGbt 5p14on
VOtVgmxD 4mmqvI4F
zMBfwzz8 OHcMg
HfjWeo9C A69vgRSf
Xdyd0f4G LbHz3oSf
x4rydoeR EXTUFgRn
wIY0iS C9EEbGHM
eaOQHlQi uTg4Qd
SJrdNldT mWxFebmg
mFmV3pg YEIqctZU
Fxx76giB jhkW769p
j63Hz4jI AxCQ33N9
c7UP07nX i40xu3Gu

mmyCWnwt 19fOdvcK
ULcttpYI yMtBemsJ
PTaNwd hlqMAfRi
2EI0158j r7FE4Smw
s4uTYMs4 FmB6StW
AtxthU6C UYaWBiOj
aZT5c9H9 thu7rZGo
tO9qrEmQ CHaIeU
vO9iizmE PMzcr0Ju

uro5IK rn74yAJK
H01MlbVn wpHlNrwf
ZE5wvCi0 6aPZL
Nfdcwugm Ox8HZd9r
lzEj8IJy a54mCQwE
Hb7JEj dYvbu3YE
5oy1IF2h Dq6qND7I
DdMbx7sQ pWUudHem
RnT67VlZ 0UOXuxpD
oTc6k POWGDL0r
DU2oJTUB S5GKjsm
ebDASW7J iWKIk2lP
bx9ltK71 ndjKyyQQ
0c44PR 2rZQmp
zadUWe9W roVNP7ao
gd63gQJH dz2NEfbT
pp7Hp4Xa axvqZbEr
cfBKj 3ZKZyYDr
dQLyrBPP asf789
uro5IK rn74yAJK
H01MlbVn wpHlNrwf
ZE5wvCi0 6aPZL
Nfdcwugm Ox8HZd9r
5465456 jioert75
================分隔符=====================
如上,有50行数据(空行也算是一行数据),已存放在某个txt文件中,观察如上数据,分为帐号列和密码列,一一对应,中间由一个或多个空格间隔开。
帐号和密码组成元素是大写字母、小写字母、数字;如果空行,也要读取出帐号和密码,值都为“空”
求前辈帮助:将帐号和密码分别一一对应写入到50个对应的数组中,譬如:
PMID1=bbXyJoFm
PMPS1=lz7YFB6u
PMID2=空
PMPS2=空
PMID3=iqAIZGbt
PMPS3=5p14on
求代码,谢谢前辈~关键处请加上注释哦~谢谢~
补充一下:帐号,也可能是中文汉字~
...全文
355 点赞 收藏 6
写回复
6 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
qq_29298783 2018-04-09
感谢楼上前辈~我现在就试试~
回复
of123 2018-04-09
Dim PMID() As String, PMPS() As String

Private Sub Command1_Click()
Dim strLine As String, strTmp() As String, bytTmp() As Byte
Dim n As Long

'check the length of the txt file
Open "c:\test\test\tmp\testdata.txt" For Input As #1
Do Until EOF(1)
    Line Input #1, strLine
    n = n + 1
Loop
Close #1

ReDim PMID(n - 1)
ReDim PMPS(n - 1)

n = 0
Open "c:\test\test\tmp\testdata.txt" For Input As #1
Do Until EOF(1)
    Line Input #1, strLine
    If Trim(strLine) > " " Then
        Do While InStr(strLine, Space(2)) > 0
            strLine = Replace(strLine, Space(2), Space(1))
        Loop
        strLine = Replace(strLine, Space(1), vbTab)

        strTmp = Split(strLine, vbTab)
        
        PMID(n) = strTmp(0)
        PMPS(n) = strTmp(1)
    Else
        PMID(n) = ""
        PMPS(n) = ""
    End If
    
    n = n + 1
Loop
Close #1

For n = 0 To UBound(PMID)
    Debug.Print "PMID" & CStr(n + 1) & " = " & PMID(n), "PMPS" & CStr(n + 1) & " = " & PMPS(n)
Next n
End Sub
PMID1 = bbXyJoFm            PMPS1 = lz7YFB6u
PMID2 =       PMPS2 = 
PMID3 = iqAIZGbt            PMPS3 = 5p14on
PMID4 = VOtVgmxD            PMPS4 = 4mmqvI4F
PMID5 = zMBfwzz8            PMPS5 = OHcMg
PMID6 = HfjWeo9C            PMPS6 = A69vgRSf
PMID7 = Xdyd0f4G            PMPS7 = LbHz3oSf
PMID8 = x4rydoeR            PMPS8 = EXTUFgRn
PMID9 = wIY0iS              PMPS9 = C9EEbGHM
PMID10 = eaOQHlQi           PMPS10 = uTg4Qd
PMID11 = SJrdNldT           PMPS11 = mWxFebmg
PMID12 = mFmV3pg            PMPS12 = YEIqctZU
PMID13 = Fxx76giB           PMPS13 = jhkW769p
PMID14 = j63Hz4jI           PMPS14 = AxCQ33N9
PMID15 = c7UP07nX           PMPS15 = i40xu3Gu
PMID16 =      PMPS16 = 
PMID17 = mmyCWnwt           PMPS17 = 19fOdvcK
PMID18 = ULcttpYI           PMPS18 = yMtBemsJ
PMID19 = PTaNwd             PMPS19 = hlqMAfRi
PMID20 = 2EI0158j           PMPS20 = r7FE4Smw
PMID21 = s4uTYMs4           PMPS21 = FmB6StW
PMID22 = AtxthU6C           PMPS22 = UYaWBiOj
PMID23 = aZT5c9H9           PMPS23 = thu7rZGo
PMID24 = tO9qrEmQ           PMPS24 = CHaIeU
PMID25 = vO9iizmE           PMPS25 = PMzcr0Ju
PMID26 =      PMPS26 = 
PMID27 = uro5IK             PMPS27 = rn74yAJK
PMID28 = H01MlbVn           PMPS28 = wpHlNrwf
PMID29 = ZE5wvCi0           PMPS29 = 6aPZL
PMID30 = Nfdcwugm           PMPS30 = Ox8HZd9r
PMID31 = lzEj8IJy           PMPS31 = a54mCQwE
PMID32 = Hb7JEj             PMPS32 = dYvbu3YE
PMID33 = 5oy1IF2h           PMPS33 = Dq6qND7I
PMID34 = DdMbx7sQ           PMPS34 = pWUudHem
PMID35 = RnT67VlZ           PMPS35 = 0UOXuxpD
PMID36 = oTc6k              PMPS36 = POWGDL0r
PMID37 = DU2oJTUB           PMPS37 = S5GKjsm
PMID38 = ebDASW7J           PMPS38 = iWKIk2lP
PMID39 = bx9ltK71           PMPS39 = ndjKyyQQ
PMID40 = 0c44PR             PMPS40 = 2rZQmp
PMID41 = zadUWe9W           PMPS41 = roVNP7ao
PMID42 = gd63gQJH           PMPS42 = dz2NEfbT
PMID43 = pp7Hp4Xa           PMPS43 = axvqZbEr
PMID44 = cfBKj              PMPS44 = 3ZKZyYDr
PMID45 = dQLyrBPP           PMPS45 = asf789
PMID46 = uro5IK             PMPS46 = rn74yAJK
PMID47 = H01MlbVn           PMPS47 = wpHlNrwf
PMID48 = ZE5wvCi0           PMPS48 = 6aPZL
PMID49 = Nfdcwugm           PMPS49 = Ox8HZd9r
PMID50 = 5465456            PMPS50 = jioert75
回复
qq_29298783 2018-04-09
多谢楼上前辈~我的确是小菜鸟~以后会好好努力学习~多谢您~
回复
舉杯邀明月 2018-04-08
引用 楼主 qq_29298783 的回复:
bbXyJoFm lz7YFB6u iqAIZGbt 5p14on VOtVgmxD 4mmqvI4F zMBfwzz8 OHcMg . . . . . . . . . ZE5wvCi0 6aPZL Nfdcwugm Ox8HZd9r 5465456 jioert75 ================分隔符===================== 如上,有50行数据(空行也算是一行数据),已存放在某个txt文件中,观察如上数据,分为帐号列和密码列,一一对应,中间由一个或多个空格间隔开。 帐号和密码组成元素是大写字母、小写字母、数字;如果空行,也要读取出帐号和密码,值都为“空” 求前辈帮助:将帐号和密码分别一一对应写入到50个对应的数组中,譬如: PMID1=bbXyJoFm PMPS1=lz7YFB6u PMID2=空 PMPS2=空 PMID3=iqAIZGbt PMPS3=5p14on 求代码,谢谢前辈~关键处请加上注释哦~谢谢~ 补充一下:帐号,也可能是中文汉字~
楼主,你学过“编程”吗? 你这不是“数组”!而是一个个的独立变量。 要“分隔” ID和密码,一点儿也不难, 如果“程序代码”中这样进行赋值,很繁琐; 用“数组”就很方便了。 当然,如果“从文本文件读取数据”,照你那样的格式输出到另一个文本文件中,也简单…… 具体怎样,就看你的实际是啥样的需求了。
回复
qq_29298783 2018-04-08
求前辈们加上注释哦~谢谢~
回复
qq_29298783 2018-04-08
补充一下:帐号,也可能是中文汉字~ 谢谢~
回复
相关推荐
发帖
VB基础类
创建于2007-09-28

7518

社区成员

VB 基础类
申请成为版主
帖子事件
创建了帖子
2018-04-08 10:24
社区公告
暂无公告