用下面方法可以证: 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
****************************************
这个没有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*************************************************用 口香糖 的方法
应该这样用:left(space,instr(1,space,vbnullchar)-1)
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
例如:
Dim a As String * 8
a = Space(8)
a = Trim(a)
MsgBox "123" & a & "123"
打印出来的会是"123 123"
debug.print Len(Replace(str1, str2, Space(Len(str2) + 1))) - Len(str1)
str1,str2还是原来那样不变的