VB取子字符串
在VB中 怎么从"F:\temp\del\SZOFFICE\projdocs\testDB\XXXX.DBF"中取到XXXX字符串初学VB 求指教 --------------------编程问答-------------------- --------------------编程问答--------------------
--------------------编程问答--------------------
Private Sub Command1_Click()
Dim strP As String
Dim intP As Integer
Dim strA() As String
Dim strB() As String
On Error GoTo errSub
strP = "F:\temp\del\SZOFFICE\projdocs\testDB\XXXX.DBF"
strA = Split(strP, "\")
strB = Split(strA(UBound(strA)), ".")
Debug.Print strB(0)
Exit Sub
errSub:
End Sub
Private Declare Sub PathStripPath Lib "shlwapi.dll" Alias "PathStripPathA" (ByVal pszPath As String)--------------------编程问答-------------------- 我也在弄这个……稀里糊涂的 --------------------编程问答--------------------
Public Function GetFilenameFromPath(ByVal sFilePath As String, Optional ByVal bWithExtension As Boolean = True, Optional ByVal enmCase As VbStrConv = vbLowerCase) As String
'---------------------------------------------------------------------------------------
' Author : Ruturaaj
' Email : ruturajvpatki@hotmail.com
' Website : http://www.rcreations.co.nr
'=======================================================================================
' Procedure : GetFilenameFromPath
' Type : Function
' ReturnType : String
'=======================================================================================
' Purpose : Extract File name from given File path.
'---------------------------------------------------------------------------------------
On Error GoTo GetFilenameFromPath_Error
PathStripPath sFilePath
sFilePath = Mid$(sFilePath, 1, InStrRev(sFilePath, Chr$(0)) - 1)
If bWithExtension Then
GetFilenameFromPath = StrConv(sFilePath, enmCase)
Else
If InStr(sFilePath, ".") = 0 Then
GetFilenameFromPath = StrConv(sFilePath, enmCase)
Else
GetFilenameFromPath = StrConv(Mid$(sFilePath, 1, InStrRev(sFilePath, ".") - 1), enmCase)
End If
End If
'This will avoid empty error window to appear.
Exit Function
GetFilenameFromPath_Error:
'Show the Error Message with Error Number and its Description.
MsgBox "Error on Line " & Erl & vbCrLf & vbCrLf & Err.Description, vbCritical, "GetFilenameFromPath Function"
'Safe Exit from GetFilenameFromPath Function
Exit Function
End Function
Option Explicit--------------------编程问答-------------------- 问题已解决
Private Sub Command1_Click()
Dim FilePath As String, S As String
Dim Arr() As String
FilePath = "F:\temp\del\SZOFFICE\projdocs\testDB\XXXX.DBF"
S = Right(FilePath, Len(FilePath) - InStrRev(FilePath, "\"))
Debug.Print S '结果是XXXX.DBF
Arr = Split(S, ".")
Debug.Print Arr(0) '结果是XXXX,去掉了扩展名
End Sub
fileTitle
补充:VB , 基础类