Re: Find What String Ends With

Tech-Archive recommends: Speed Up your PC by fixing your registry




How can I check if my string ends with a certain substring or letter?
There is an excellent equivalent in Java endsWith("somestring") where
you can check if string ends in desired substring, then desired action
will be performed.


As Ayush said, you can do it easily with the
Right function. I also like to add UCase to
the operation. Right seems to be case-sensitive.
Sample:

Dim s
s = "abcd"

If right(s, 1) = "D" Then
MsgBox "ok"
Else
MsgBox "no"
End If

So a thorough-going approach is to use something
like:

If UCase(Right(s, 2)) = "CD" Then....


.



Relevant Pages

  • Re: Find What String Ends With
    ... you can check if string ends in desired substring, ... As Ayush said, you can do it easily with the ... MsgBox "ok" ... because you can specify compare type and limit how much of the string is ...
    (microsoft.public.scripting.vbscript)
  • Re: Find What String Ends With
    ... There is an excellent equivalent in Java endsWithwhere ... you can check if string ends in desired substring, then desired action ... You can use Right function to get the characters at the right of string then compare the returned value. ...
    (microsoft.public.scripting.vbscript)
  • Re: Find What String Ends With
    ... There is an excellent equivalent in Java endsWithwhere ... you can check if string ends in desired substring, then desired action ...
    (microsoft.public.scripting.vbscript)
  • Re: Find What String Ends With
    ... you can check if string ends in desired substring, then desired action ... Use regex: ...
    (microsoft.public.scripting.vbscript)