我把路径保存在字符串str中,
例如:str = "c:\01\01\northwind.mdf"
请教用什么方法能取出 northwind .
例如:str = "c:\01\01\northwind.mdf"
请教用什么方法能取出 northwind .
解决方案 »
- vb窗体边框固定不可变,但是有最大最小化按钮!
- 有没有象浏览器一样的控件,可以加载一个网页到界面上
- 求MShflexgrid显示层次结构示例!!!
- ADO压缩数据库的问题
- vb 数据库开发,做事务处理,语句怎么写?谁给出一小段代码就可以了
- 软件界面规范文档应该如何写 都写些什么 那位有样本发给我参考一下 谢谢了啊!!!
- 50分求救!
- 百度百科里如何编程实现对百科内容的编辑?
- 高手请进!!!类似象棋的棋子的位置排列,棋子是动态生成,并能返回一个识别号!!!
- 我把form的BorderStyle属性设置成0-None.请教大哥,当我打开FORM时,怎样才能使点击win98的工具栏上的窗口使FORM变成最小化,(就想普通的FORM一样).
- C:\WINDOWS\Offline Web Pages文件夹的问题
- 如何从一个文本文件中或一篇文章中,识别出合法的电子邮件?
dim x as long
x =instrrev(fullpath,"\")
if x then fullpath=mid(fullpath,x+1)
x=instrrev(fullpath,".")
if x>1 then fullpath=left(fullpath,x-1)
GetFileName=fullpath
end function
'未调试
dim iPos as Integer
dim str as String,strTmp as string
str = "c:\01\01\northwind.mdf"
iPos=InstrRev(str,"\") '最后一个\的位置
if iPos<=0 then
msgbox "文件名错误"
exit function
end if
strTmp=Mid(str,iPos+1) '文件名包含扩展名
iPos=InstrRev(strTmp,".") '最后一个.的位置
if iPos>1 Then strTmp=Left(strTmp,iPos-1)
GetFileName=strTmp
End Function
dim iPos as Integer
dim str as String,strTmp as string
str = "c:\01\01\northwind.mdf"
iPos=InstrRev(str,"\") '最后一个\的位置
if iPos<=0 then
msgbox "文件名错误"
exit function
end if
strTmp=Mid(str,iPos+1) '文件名包含扩展名
iPos=InstrRev(strTmp,".") '最后一个.的位置
if iPos>1 Then strTmp=Left(strTmp,iPos-1)
GetFileName=strTmp
End Function
MsgBox Split(Mid(Str, InStrRev(Str, "\") + 1), ".")(0)
FullPath = Dir(FullPath)
GetFileName = Left(FullPath, InStr(FullPath, ".") - 1)
End Function
Private Sub Command1_Click()
MsgBox GetFileName("c:\01\01\northwind.mdf")
End Sub
不过变量名最好不要用VB的内置函数名,比如str。
MsgBox Split(Mid(Str, InStrRev(Str, "\") + 1), ".")(0)
为什么要在后面加上(0)?
答:split函数将字符串转换成一维数组。比如数组s(),s(0)当然是返回数组的第一个元素了,s(1)返回第二个元素(在这个例子里将返回扩展名"mdf")。问:你的算法很好理解,可是调试不能通过,继续求解~
答:"c:\01\01\northwind.mdf"这个路径在本机确实存在的情况下才能正常执行,所以,比狼行天下的代码差多了。