VB取子字符串

techshinocom 2012-12-10 03:52:14
在VB中 怎么从"F:\temp\del\SZOFFICE\projdocs\testDB\XXXX.DBF"中取到XXXX字符串
初学VB 求指教
...全文
306 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
techshinocom 2012-12-11
  • 打赏
  • 举报
回复
问题已解决 fileTitle
东方之珠 2012-12-10
  • 打赏
  • 举报
回复
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
yanyingjuanli 2012-12-10
  • 打赏
  • 举报
回复
我也在弄这个……稀里糊涂的
threenewbee 2012-12-10
  • 打赏
  • 举报
回复
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

贝隆 2012-12-10
  • 打赏
  • 举报
回复

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

worldy 2012-12-10
  • 打赏
  • 举报
回复
private function GetIt(s as string) as string
dim P as long
p=instrrev(s,"\")
if p>0 then
getit=right(s,p+1)
end if
end function

7,763

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧