2017-09-19 2 views
1

이것은 내가 무엇을 가지고 지난 후 문자열의 일부를 제거VBS "/"

Dim pathAfter 
pathAfter = "product/subproduct/item" 

내가 달성하기 위해 할 수있는 일 이? RegEx를 사용해 보았지만 수용 할만한 해결책이 아닙니다.

답변

0

는 지난 / 그 지점 개까지 읽을 찾기 - 1

pathAfter = left$(pathBefore, instrrev(pathBefore, "/") - 1) 
+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

+0

하지 마세요, 더 나은 (눈을보다 효율적으로/쉽게) 대안이 있습니다. –

+0

@ Ekkehard.Horner 그들에게서 배울 수있어서 기쁠 것입니다. 이것은 내 마음에 온 첫 번째 방법이었습니다. – Gurman

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 
+0

그들은 확실히 더 낫다. 이 주셔서 감사합니다 :) – Gurman