CLASS文件截取字符串问题
路径如:E:\eclipse-SDK-3.2RC4-win32\workspace\UP\build\classes\javasrc\business\com\inc\tal\baa\Query.class
E:\eclipse-SDK-3.2RC4-win32\workspace\UP\build\classes\javasrc\business\com\inc\aal\bbb\Service.java
目的:想截取去掉"E:\eclipse-SDK-3.2RC4-win32\workspace\"和文件名的中间这串路径
目前做到:
Dim fso,f,temp,fright
set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.opentextfile("D:\test.txt",1,false)
temp = f.readline()
fright = len(temp)-len("E:\eclipse-SDK-3.2RC4-win32\workspace\")
str=right(temp,fright)
'str=left(str,"11")
msgbox (str)
----------
str为:UP\build\classes\javasrc\business\com\inc\tal\baa\Query.class
再怎么做去截掉文件名呢? 喜欢研究有关字符串处理的问题。我写的代码和楼主的不太一样,只是因为我喜欢这样的处理风格,用split分割字符串获得一个数组,然后对数组进行操作,这是最爽的处理方式,比单纯的通过字符串截取要方便(个人观点)
Dim fso,f,temp,fright
set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.opentextfile("D:\test.txt",1,false)
temp = f.readline()
'fright = len(temp)-len("E:\eclipse-SDK-3.2RC4-win32\workspace\")
'str=right(temp,fright)
'str=left(str,"11")
arr = Split(temp,"\")
arrLength =UBound(arr)
For i = 3 To arrLength-1
str = str&"\"&arr(i)
next
msgbox (str)
回复 1# 的帖子
GetParentFolderName(str) GetParentFolderName(str) UP学习了
GetParentFolderName
object.GetParentFolderName(path)
根据指定路径中的最后成分返回包含其父文件夹名称的字符串。
[ 本帖最后由 helius 于 2009-2-25 19:35 编辑 ] 谢谢.学习了
页:
[1]