i have a string with "\" in it i i wanted a way to only get the last bit of test after the last "\" but the string may contain different numbers of "\" can someone help
Printable View
i have a string with "\" in it i i wanted a way to only get the last bit of test after the last "\" but the string may contain different numbers of "\" can someone help
two examples on data that i need to change
NDS:\\HUB\APHS\ST\95\gmitchell
NDS:\\HUB\APHS\Staff\twest
i need gmitchell and twest
i was thinking i have some code that will give me the cut the string in to two parts. but i will need a while wend to cheack if the string still contains "\".
Code:'if you have VB6
Private Sub Form_Load()
Dim x As String
x = "my/and that/and mylast/is not only a / but it was last"
Dim y
y = Split(x, "/")
MsgBox y(UBound(y))
End Sub
Code:'split function for VB5 and under vb6 has the function
'posted originally by Aaron Young
Public Function Split2(ByVal sString As String, ByVal sSeparator As String) As Variant
Dim sParts() As String
Dim lParts As Long
Dim lPos As Long
lPos = InStr(sString, sSeparator)
While lPos
ReDim Preserve sParts(lParts)
sParts(lParts) = Left(sString, lPos - 1)
sString = Mid(sString, lPos + Len(sSeparator))
lPos = InStr(sString, sSeparator)
lParts = lParts + 1
Wend
If Len(sString) Then
ReDim Preserve sParts(lParts)
sParts(lParts) = sString
End If
Split2 = IIf(lParts, sParts, Array())
End Function
'Example:
Private Sub Form_Load()
Dim x As String
x = "my/and that/and mylast/is not only a / but it was last"
Dim y
y = Split2(x, "/")
MsgBox y(UBound(y))
End Sub
this is the code that i found all i need to do is put a while wend loop around it to check if there is still "\" in the string.
Code:result1 = Left$(tempstr, InStr(1, tempstr, "\", vbTextCompare))
tempstr = Right$(tempstr, Len(tempstr) - Len(result1))
result1 = Left$(result1, Len(result1) - 1)
It is mucht easier. Just use the function InstrRev.