VBS - 在最后一个“/”之后删除部分字符串

时间:2017-09-19 12:11:53

标签: vbscript character

这就是我所拥有的:

String p12FilePath = "...";
String passwordCertificate= "...";

KeyStore ks = KeyStore.getInstance("PKCS12");
ks.load( new FileInputStream(p12FilePath),
         passwordCertificate.toCharArray());

这是我需要从pathBefore:

获得的
Dim pathBefore
pathBefore = "product/subproduct/item/item"

我能做些什么来实现这个目标? 我已尝试使用RegEx,但这是不可接受的解决方案。

3 个答案:

答案 0 :(得分:2)

@Gurman:

>> s = "product/subproduct/item/item"
>> a = Split(s, "/")
>> ReDim Preserve a(UBound(a) - 1)
>> WScript.Echo Join(a, "/")
>> WScript.Echo goFS.GetParentFolderName(s)
>> WScript.Echo Left(s, InstrRev(s, "/") - 1)
>>
product/subproduct/item
product/subproduct/item
product/subproduct/item

答案 1 :(得分:1)

试试这段代码:

Dim pathBefore, pathAfter, temp, i
pathBefore = "product/subproduct/item/item"
temp = Split(pathBefore,"/")
For i=0 To UBound(temp)-1
    pathAfter = pathAfter & temp(i) & "/"
Next
pathAfter = Left(pathAfter,Len(pathAfter)-1)
MsgBox pathAfter

输出:

enter image description here

答案 2 :(得分:0)

找到最后一个/然后读到那一点 - 1

pathAfter = left$(pathBefore, instrrev(pathBefore, "/") - 1)