注册 登录
编程论坛 VB6论坛

求助!遍历txt里的字符,只保留数字、字母、和汉字,删除其他字符(如回车,空格等)

q173641439 发布于 2018-06-05 11:00, 3424 次点击
只有本站会员才能查看附件,请 登录
程序代码:
'Kp输出
Public Sub passive_Kp_output(error_happen As Boolean, bottom_layer As Integer, layers_number As Integer, H() As Double, Kp() As Double, soil_name() As String)
If layers_number = 0 Then
    Exit Sub
Else

 Form1.Text1.Text = Form1.Text1.Text & vbCrLf & "1.2各土层Kp值" & vbCrLf
    For i = 1 To layers_number - bottom_layer + 1 Step 1
        If i = 1 Then
            For j = 1 To bottom_layer Step 1
                temp = temp + H(j)
            Next j
            first_in_layers_thickness = temp - L '第一层坑内土表面到该层层底的实际厚度
            Form1.Text1.Text = Form1.Text1.Text & "" & i & "层(" & first_in_layers_thickness & "m" & soil_name(i + bottom_layer - 1) & "):" & "  "
            Form1.Text1.Text = Form1.Text1.Text & "Kp_" & i & "=" & Format(Kp(i), "0.000") & vbCrLf
        Else
            Form1.Text1.Text = Form1.Text1.Text & "" & i & "层(" & H(i + bottom_layer - 1) & "m" & soil_name(i + bottom_layer - 1) & "):" & "  "
            Form1.Text1.Text = Form1.Text1.Text & "Kp_" & i & "=" & Format(Kp(i), "0.000") & vbCrLf
        End If
    Next i
End If
End Sub
   可以看到并没有换行操作,,为什么还是有换行呢

[此贴子已经被作者于2018-6-5 11:04编辑过]

3 回复
#2
风吹过b2018-06-05 11:11
看你的代码和结果,在 ): 这里换的行,检查
soil_name(i + bottom_layer - 1)
里面是否包含 vbcrlf 。
如果不包含,那就说明 文本框宽度不够。
可以设断点检查变量值和以及检查变量长度等来检验,甚至可以转为二进制数组来查看每个字符的编码以确定是包含 不打印字符。

如果这个变量里面包含 vbcrlf ,如果位置固定,比如在尾部,用 left 函数去掉。
如果位置不固定,那使用 Replace 函数去掉。

#3
wds12018-06-05 11:12
用debug.print按字节打印看看是否有
例如:for i=1 to len(temp):debug.print asc(mid(temp,i,1)):next

如果过滤掉简单的几个,建议用替换
temp=replace(temp," ","")
temp=replace(temp,vbcrlf,"")


 
#4
Artless2018-06-05 22:52
你图中红框是ka代码是kp
1