如果删除 space产生的空格?请各位高手支招

解决方案 »

  1.   

    strTest = replace(strtest," ","")
      

  2.   

    这并不是由于space产生的问题,而是由于空格在中间。
    ****************************************
    这个没有space,一样去不掉
    Private Sub Command1_Click()
        Dim strTemp As String    strTemp = "asdf    df"
        Debug.Print strTemp
        Debug.Print Trim(strTemp)
    End Sub**************************************
    这个用space,因为在结尾也能去掉
    Private Sub Command1_Click()
        Dim strTemp As String    strTemp = "asdf" & Space(10)
        Debug.Print strTemp
        Debug.Print Trim(strTemp) & "end"
    End Sub*************************************************用 口香糖 的方法
      

  3.   

    定长字符串吧,Trim对定长字符串无效。
    应该这样用:left(space,instr(1,space,vbnullchar)-1)
      

  4.   

    用下面方法可以证:
    Option Explicit
    Private Declare Function GetWindowsDirectory Lib "kernel32.dll" Alias "GetWindowsDirectoryA" (ByVal lpBuffer As String, ByVal nSize As Long) As LongPrivate Sub Form_Load()
            Dim WinDir As String * 256, S As String
            Call GetWindowsDirectory(WinDir, 256)
            S = Trim(WinDir)
            Debug.Print Len(S) '结果为256
            Debug.Print Len(Left(WinDir, InStr(WinDir, vbNullChar) - 1)) '结果为10
    End Sub
      

  5.   

    既然用了space函数为什么又要把其中的空格去掉呢,如果是有它用,可以把space函数放到别的函数或方法中的,这样就不会把本身的字符改变了
      

  6.   

    trim不能用的话,你看看是不是定义了字符的长度
    例如:
        Dim a As String * 8
        a = Space(8)
        a = Trim(a)
        MsgBox "123" & a & "123"
    打印出来的会是"123        123"
      

  7.   

    例如:想知道字符串str1中有多少个字符串str2
    debug.print Len(Replace(str1, str2, Space(Len(str2) + 1))) - Len(str1)
    str1,str2还是原来那样不变的