这是我以前用的,特别是用在与C融合中 '用来除去右边空格 Public Function MyRTrim(s As String) As String Dim i As Integer Dim t As String * 1
i = Len(s) t = Mid(s, i, 1) Do While (t = Chr(0) Or t = Chr(32) Or t = Chr(255)) '以\0作为字符串结束符 'Debug.Print Asc(Mid(s, i, 1)); i = i - 1 If i = 0 Then Exit Do t = Mid(s, i, 1) Loop If i > 0 Then ghpRTrim = Left(s, i) End Function
Function htrim(ByVal str As String) As String '处理字符串 Dim lenth As Integer lenth = Len(str) Dim i As Integer For i = 1 To lenth If Asc(Mid(str, Len(str), 1)) = 0 Or Asc(Mid(str, Len(str), 1)) = 32 Then str = Mid(str, 1, Len(str) - 1) Else Exit For End If Next ihtrim = str End Function ------------------一定行
我终于明白了,是因为有回车,换行符吧 修改sdyqingdao的程序Function htrim(ByVal str As String) As String '处理字符串 Dim lenth As Integer lenth = Len(str) Dim i As Integer Dim char As Integer dim s as string For i = 1 To lenth char=Asc(Mid(str, i, 1)) If char<>0 and char<>32 and char<>10 and char<>13 Then s =s & Mid(str, i, 1) end if Next i htrim = s End Function
我刚试过,就是回车符。 用MID(TEXT1,1,LEN(TEXT1)-1)就可以了或用Function htrim(ByVal str As String) As String '处理字符串 Dim lenth As Integer lenth = Len(str) Dim i As Integer Dim char As Integer dim s as string For i = 1 To lenth char=Asc(Mid(str, i, 1)) If char<>0 and char<>32 and char<>10 and char<>13 Then s =s & Mid(str, i, 1) end if Next i htrim = s End Function 也行,一定要给分哦!!!
text1.text=trim(text1.text)不就去掉两边空格了吗
Jneu(River):这个应该怎么用???请指点!!!
'用来除去右边空格
Public Function MyRTrim(s As String) As String
Dim i As Integer
Dim t As String * 1
i = Len(s)
t = Mid(s, i, 1)
Do While (t = Chr(0) Or t = Chr(32) Or t = Chr(255)) '以\0作为字符串结束符
'Debug.Print Asc(Mid(s, i, 1));
i = i - 1
If i = 0 Then Exit Do
t = Mid(s, i, 1)
Loop If i > 0 Then ghpRTrim = Left(s, i)
End Function
应该没问题
Dim lenth As Integer
lenth = Len(str)
Dim i As Integer
For i = 1 To lenth
If Asc(Mid(str, Len(str), 1)) = 0 Or Asc(Mid(str, Len(str), 1)) = 32 Then
str = Mid(str, 1, Len(str) - 1)
Else
Exit For
End If
Next ihtrim = str
End Function
------------------一定行
********************************************************************
我在用复制和粘贴的时候产生空格。这样,用文本框中的内容作为查询条件的时候就产生了问题。我想去掉空格。可是只是去掉了左边的空格。我需要全部去掉空格
********************************************************************
请注意!我在用复制和粘贴的时候产生空格。所以我用trim不起作用。因为我是要用文本框中的内容作为一个查询条件!用复制和粘贴文字的时候产生空格。可是用trim不起作用。我的查询条件里面用了trim。可是还是不行!
判断=0或=32应该就行了
修改sdyqingdao的程序Function htrim(ByVal str As String) As String '处理字符串
Dim lenth As Integer
lenth = Len(str)
Dim i As Integer
Dim char As Integer
dim s as string
For i = 1 To lenth
char=Asc(Mid(str, i, 1))
If char<>0 and char<>32 and char<>10 and char<>13 Then
s =s & Mid(str, i, 1)
end if
Next i
htrim = s
End Function
sdyqingdao(免费,免费):我再试一试!!!谢谢了!!!
用MID(TEXT1,1,LEN(TEXT1)-1)就可以了或用Function htrim(ByVal str As String) As String '处理字符串
Dim lenth As Integer
lenth = Len(str)
Dim i As Integer
Dim char As Integer
dim s as string
For i = 1 To lenth
char=Asc(Mid(str, i, 1))
If char<>0 and char<>32 and char<>10 and char<>13 Then
s =s & Mid(str, i, 1)
end if
Next i
htrim = s
End Function
也行,一定要给分哦!!!
我要结账了。。
xlain(lain) 得因该可以