原创 (VB自定义函数)去除字符串中的空格

2009-8-17 16:57 10703 23 23 分类: 软件与OS

'去除字符串中的空格(方法一)
Public Function DelBlank(SearchString As String)
   DelBlank = Replace(SearchString, Chr(32), "")
End Function


'去除字符串中的空格(方法二)
Public Function DelBlank(SearchString As String)


    Dim Strtemp As String
    Dim LenTemp As Integer
    Dim Blank() As String
    LenTemp = Len(SearchString)
    Strtemp = SearchString
    ReDim Blank(LenTemp - 1)
    For i = 1 To LenTemp
        Strtemp = Left(Strtemp, 1)
        If Not Strtemp = " " Then
            Blank(i - 1) = Strtemp
        End If
        Strtemp = Right(SearchString, LenTemp - i)  
    Next
    For i = 0 To LenTemp - 1
        DelBlank = DelBlank + Blank(i)
    Next
    DelBlank = Trim(DelBlank)
End Function


1.用自定义函数
Public Function mytrim(ByVal vstr As String) As String
Dim a As Integer
Dim lstr As String
    a = Len(vstr)
    For i = 1 To a
       k = Mid(vstr, i, 1)
       If k <> " " Then lstr = lstr & k
    Next
    mytrim = lstr
End Function
 
2,用VB自带函数


replace(lstr," ","")

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
23
关闭 站长推荐上一条 /3 下一条