prss.net
当前位置:首页 >> 用VB编程,去掉文本框中数据间的空格 >>

用VB编程,去掉文本框中数据间的空格

我有一个思路 把文本框的文本一个字符一个字符的判定,是空格键的一概删除 dim str as string,Tstr as string,ttstr as string tstr=text1.text '读文本 dim i as int if len(str)

‘用replace ’TextBox1输入 ‘TextBox2输出 Dim Num As String Num = TextBox1.Text Num = Num.Replace(" ", "") TextBox2.Text = Num

trim去2边空格 replace(文本," ","") 去掉所有空格 包括文本中间的。

Private Sub Command1_Click() MsgBox TrimBlank("aa bb cc") End Sub Public Function TrimBlank(ByVal sTxt As String) As String Do While InStr(sTxt, " ") 0 sTxt = Replace(sTxt, " ", " ") Loop TrimBlank = sTxt End Function

Trim() 可以去掉空格 Print #2, Trim(d1), x, Trim(d2), x, Trim(d3), x, Trim(d4), x, Trim(d5), x, Trim(d6), x, Trim(d7), x,

两端的空格用trim()函数去掉。 中间空格可以用replace()替换掉。

text1.text=replace(text1.text," ","") 即可去除掉textbox控件中所有空格

Private Sub Command1_Click() Dim i As Long Dim t As String Dim a Open "123.txt" For Input As #1 Do Until EOF(1) Line Input #1, t a = Split(t, " ") Text1(i) = a(0) Text2(i) = a(1) Text3(i) = a(2) i = i + 1 Loop End Sub

思路:通过Key_Press事件捕获键盘输入,如果键盘输入的是空格,则调用按钮命令 步骤如下: Private Sub Form_KeyPress(KeyAscii As Integer) If KeyAscii = 32 Then'空格键的ASCII码为32 call Command1_click '调用命令 end if End Sub

Text1.Text = Replace(Text1.Text, vbTab, " ")

网站首页 | 网站地图
All rights reserved Powered by www.prss.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com