十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
思路与方法:
西盟ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18982081108(备注:SSL证书合作)期待与您的合作!
1,一行为读取单位,读取并保存到数组。
2,逆序循环,可以获得末尾空白行数。
3,以行为写单位,写入到文件。
Private Sub Command1_Click()
'仅去掉每一行前面的空格
Dim ary() As String
Dim i As Long
Me.List1.Clear
ary = Split(Me.Text1.Text, vbCrLf)
Text1 = ""
For i = LBound(ary) To UBound(ary)
Text1 = Text1 LTrim(ary(i)) vbCrLf
Next
End Sub
Private Sub Command2_Click()
'去掉全部空格
Text1.Text = Replace(Replace(Text1.Text, vbTab, ""), " ", "")
End Sub
Private Sub Command3_Click()
'去掉所有空行
Do While InStr(Text1.Text, vbCrLf vbCrLf) 0
Text1.Text = Replace(Text1.Text, vbCrLf vbCrLf, vbCrLf)
Loop
End Sub
Private Sub Form_Load()
'在text1中产生几个有前导空格的数据。
For i = 1 To 10
Text1 = Text1 Chr(13) Chr(10) String(Int(Rnd * 5), " ") 5 * i ","
Next i
End Sub
Private Sub Command1_Click()
Dim tx() As String, tmp As String, n As Integer
'首先将txt文件里面非空行的内容读进数组tx里
Open "d:\a.txt" For Input As #1
n = 0
Do While Not EOF(1)
Line Input #1, tmp
If tmp "" Then
ReDim Preserve tx(n)
tx(n) = tmp
n = n + 1
End If
Loop
Close #1
'然后就清空txt文件,把数组tx里面的内容写进去就可以了
Open "d:\a.txt" For Output As #2
Cls
For i = 0 To UBound(tx)
Print #2, tx(i)
Next
Close #2
'如果你是要将过滤了空行的内容读进文本框里面,那么:
For i = 0 To UBound(tx)
Text1.Text = Text1.Text tx(i) vbCrLf
Next
End Sub
你是要把连续多个空格,变换成只需要一个空格,那么:
do while Instr(tStr," ")0
tStr = Replace(tStr, " ", " ") '用一个空格,替换2个空格
loop