求教高手,如何取得(只取得)字符串里的指定后缀名的文件名,谢谢!!!

ahbc123 2003-11-28 07:40:15
求教高手,如何取得(只取得)以下字符串里的以".jpg",".swf",".gif"为后缀名的文件名(butterfly_01.jpg,flash18[1].swf,Hlpstep1.gif),谢谢!!!

<HTML>
<HEAD>

<TITLE></TITLE>
</HEAD>
<BODY>
<P><IMG align=baseline alt="" border=0 hspace=0
src="..\temp\butterfly_01.jpg">  <EMBED height=50
src=..\temp\flash18[1].swf width=128><EMBED height=50 src=..\temp\sss.swf
width=128><IMG align=baseline alt=""
border=0 hspace=0 src="..\temp\Hlpstep1.gif"> </P>
</BODY>
</HTML>
...全文
209 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
northwolves 2003-11-30
  • 打赏
  • 举报
回复
Private Sub Command1_Click()
Dim x As String
x = Text1.Text
findfile x, "swf"
findfile x, "gif"
findfile x, "jpg"
End Sub

Sub findfile(ByVal x As String, ByVal exp As String)
Dim temp
temp = Split(x, "." & exp)
For i = 0 To UBound(temp) - 1
If InStrRev(temp(i), "\") > 0 Then MsgBox Right(temp(i), Len(temp(i)) - InStrRev(temp(i), "\")) & "." & exp
Next
End Sub
northwolves 2003-11-30
  • 打赏
  • 举报
回复
split+ instrrev()
Maconel 2003-11-29
  • 打赏
  • 举报
回复
设置一个数组比如strHZ(0 to 2)
dim strHZ(0 to 2)
strHZ(0)="swf"
strHZ(1)="gif"
strHZ(2)="jpg"
在我上边的程序最外围加个循环
for i=0 to 2
str2=strHZ(i)
上边的程序
next i
dlpseeyou 2003-11-29
  • 打赏
  • 举报
回复
Right(rtrim(str,4))
yoki 2003-11-29
  • 打赏
  • 举报
回复
Private Sub Form_Load()
'调用:
ListAllFile "dsfds-23\sdf.jpg;sdfiyc.\ccdd.jpg\sdfds.swf,\seelll...df\ppp.gif", "jpg"
ListAllFile "dsfds-23\sdf.jpg;sdfiyc.\ccdd.jpg\sdfds.swf,\seelll...df\ppp.gif", "gif"
ListAllFile "dsfds-23\sdf.jpg;sdfiyc.\ccdd.jpg\sdfds.swf,\seelll...df\ppp.gif", "swf"
End Sub



Private Function GetFileName(strSourceText As String, strSuffix) As String()
'返回目标字符串中指定后缀的所有文件名存入数组中
Dim strResult() As String
Dim strTempFor As String
Dim intResult As Integer
Dim i As Integer
Dim j As Integer
Dim strTempDo As String
strTempDo = strSourceText
intResult = 0
Do
intResult = InStr(intResult + 1, strTempDo, strSuffix, vbBinaryCompare)
If intResult = 0 Then Exit Do
For i = intResult - 1 To 1 Step -1
strTempFor = Mid(strTempDo, i, 1)
If strTempFor = "\" Then Exit For
Next i
ReDim Preserve strResult(j)
strResult(j) = Mid(strTempDo, i + 1, intResult - i + Len(strSuffix) - 1)
strTempDo = Right(strTempDo, Len(strTempDo) - Len(strResult(j)) - i)
intResult = 0
j = j + 1
Loop
GetFileName = strResult
End Function
Private Sub ListAllFile(strSourceText As String, strSuffix As String)
Dim i As Integer
Dim arryTemp() As String
arryTemp = GetFileName(strSourceText, strSuffix)
For i = 0 To UBound(GetFileName(strSourceText, strSuffix))
Debug.Print arryTemp(i)
Next i
End Sub
yoki 2003-11-29
  • 打赏
  • 举报
回复
用楼上的代码调用3次嘛
ahbc123 2003-11-29
  • 打赏
  • 举报
回复
谢谢各位高手帮助,可能是我的意思表达的不清楚,(单独取得一种后缀名的,我会),我的意思是如何一次同时取得指定(不同后缀名)后缀名的文件名,还请高手给与再次帮助,谢谢!!!


即一次取得:
butterfly_01.jpg
flash18[1].swf
sss.swf
Hlpstep1.gif



Maconel 2003-11-28
  • 打赏
  • 举报
回复
text1中是你的这一段文字,text2中是要找的后缀名
Private Sub Command1_Click()
Dim Str1 As String
Dim Str2 As String
Dim strResult
Dim tmpStr As String
Dim intResult As Integer
Str1 = Text1
Str2 = Text2
intResult = 0
Do
intResult = InStr(intResult + 1, Str1, Str2, vbBinaryCompare)
If intResult = 0 Then Exit Do
For i = intResult - 1 To 1 Step -1
tmpStr = Mid(Str1, i, 1)
If tmpStr = "\" Then Exit For
Next i
strResult = Mid(Str1, i + 1, intResult - i + Len(Str2) - 1)
MsgBox strResult
Loop
End Sub
踏平扶桑 2003-11-28
  • 打赏
  • 举报
回复
用instr()函数来提取
具体你可以看instr的使用方法
hcj2002 2003-11-28
  • 打赏
  • 举报
回复
在字符串从后面取4个字符
Right(str,4)

7,763

社区成员

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

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