Private Sub Test()
Dim StrText As String = "TestCalls"
MsgBox(Strings.Left(StrText, Len(StrText) - 5))
End Sub
'This is the more BASIC approach... ;-)
In order to cut off the 'Calls' part, you need to know the length of the
string: Len does that for you.
Since 'Calls' is 5 characters long, you substract this value from the
string length: And voilà, the MessageBox shows 'Test'.
In order to manipulate strings, there are 3 commands available:
- Strings.Left
- Strings.Mid
- Strings.Right
Of course, you could also use the DotNet version Substring. However, the
BASIC commands do some additional checks for you (e.g. if a string is
Nothing).
Try this:
Dim StrText2 As String = Nothing
MsgBox(Strings.Left(StrText2, 2)) 'MsgBox shows an empty text.
MsgBox(StrText2.Substring(0, 2)) 'Run-time error:
'Object reference not set to an instance of an object.
Best regards,
Martin