注册 登录
编程论坛 VB6论坛

字符串 split无法用tab分拆

cuituo 发布于 2023-10-07 09:51, 885 次点击
字符串Gridshuju
1    IS50-32-125    7.5    2.08    22    2900    .96    2.2    47    2    32.5    13004                    125            50    32                    


            Gridshuju = Split(global_Shuju, "\t", -1, 0)                                  '数据分解,-1  返回所有字符串,\t,\根据TAB 进行分割
            
            Gridshuju = Split(Replace(global_Shuju, " ", "_"), "_", -1, 0)               '数据分解 尝试替换 也不行
            
            MsgBox Gridshuju(1) & Gridshuju(2)                 '提示  下标越界

            For j = 1 To UBound(Gridshuju) Step 1                                         'UBound 函数  鼠标指向,显示为0  说明未分拆
3 回复
#2
apull2023-10-07 10:19

一次不行搞两次。
程序代码:


Gridshuju = Split(global_Shuju, " ")
s = ""
For i = 0 To UBound(Gridshuju)
    If Len(Gridshuju(i)) > 0 Then
        s = s + Gridshuju(i) + " "
    End If
Next i
Gridshuju = Split(Trim(s), " ")

#3
cuituo2023-10-07 11:59
回复 2楼 apull
这段代码 ,单独可以过,但是 到我这边还是提示下标越界,我是从文本文件中 ,line input 读入的,粘贴到论坛后tab变成了空格,用空格可以分拆,读文件用空格就不行了,用tab("\t")  也不可以。


      
        PUMPFILE = App.Path & "\技术参数\" & "is型水泵资料.GDT"
        
        global_PUMPFILE = PUMPFILE
        
        Open CStr(global_PUMPFILE) For Input As #1 Len = -1
        
        Input #1, global_Rowsnum, global_Colsnum, str1, str2
        
        Line Input #1, global_ShuoMing1
        
        Line Input #1, global_ShuoMing2
        
      
        
        var_4C = global_PumpNum
        
        For i = 1 To global_PumpNum Step 1                                                '写序号
            
            Line Input #1, global_Shuju
            
            'MsgBox global_Shuju
            
            ' Gridshuju = Split(global_Shuju, "\t", -1, 0)                                  '数据分解,UBound(global_Gridbiaotilan),-1  返回所有字符串,1  按执行文字比较,\t,\根据TAB 进行分割
            
            ' MsgBox Replace(global_Shuju, " ", "_")
            
            'Gridshuju = Split(Replace(global_Shuju, " ", "_"), "_", -1, 0)                '数据分解,UBound(global_Gridbiaotilan),-1  返回所有字符串,1  按执行文字比较,\t,\根据TAB 进行分割
            
            
            
            
            Gridshuju = Split(Trim(global_Shuju), "\t")
            s = ""
            For k = 0 To UBound(Gridshuju)
                If Len(Gridshuju(i)) > 0 Then
                    s = s + Gridshuju(i) + " "
                End If
            Next k
            Gridshuju = Split(Trim(s), " ")
            
            
            
            查询界面.ziliao1.TextMatrix(i, 0) = CStr(i)
            
            MsgBox Gridshuju(1) & Gridshuju(2)
            
            
            
            For j = 1 To UBound(Gridshuju) Step 1                                         'LBound 函数与 UBound 函数一起使用,用来确定一个数组的大小。UBound 用来确定数组某一维的上界。
               
                查询界面.ziliao1.TextMatrix(i, 1) = Gridshuju(j)
               
            Next
        Next
        Close #1
        
只有本站会员才能查看附件,请 登录


[此贴子已经被作者于2023-10-7 20:44编辑过]

#4
cuituo2023-10-08 08:18
已完美解决,使用vbTab  作为分隔符,无敌的百度。


  Gridshuju = Split(global_Shuju, vbTab, -1, 0)                                 '数据分解,-1  返回所有字符串,\t 不行,vbTab 进行分割 完美解决

[此贴子已经被作者于2023-10-8 08:20编辑过]

1