I have some string. For example:
I want to read last 6 symbols in each string and put it into the string variable.
You can use the Right function in VBA:
Dim str As Stringstr = "monitor 27-14.sldasm"Dim ext As Stringext = Right(str, 6) 'sldasm
Dim str As String
str = "monitor 27-14.sldasm"
Dim ext As String
ext = Right(str, 6) 'sldasm
I believe you want to find the extension from the file path. In this case I would recommend to find the position of the extension dynamically by finding the last occurrence of "." symbol.
The following snippet finds the extension of any file:
ext = Right(str, Len(str) - InStrRev(str, "."))
Thank you, Artem.
At first, I try to recognize exactly a file extensions but I take this strings from a list of Listbox and it's just only a set of symbols. Because of it, I decided to simply read last 6 symbols.
for some reason is not working, but this:
is working perfectly.
Also, yesterday I found following string:
ext= Mid(str, Len(str) - 5, 6)
It's work too.
You can omit the last argument of MID and get all chars from that position till the end of the string: ext = Mid(Str, InStrRev(Str, "."))
It's also workng.
But, true, in this case ext=.SLDPRT
it take this point before S
Retrieving data ...