34,333
edits
Changes
→Finding the Length of a String
== Finding the Length of a String ==
it is common to need to find out the number of characters in any given string. Visual Basic provides mechanisms for finding the length of both string variables and string literals. The length of a string literal can be obtained using the ''Len()'' function, which takes the string as an argument and returns the length:
<pre>
Dim decLength As Decimal
decLength = Len("This is a string literal")
</pre>
This technique works equally well when dealing with string variables:
<pre>
Dim decLength As Decimal
Dim strMyString As String = "This is a String Variable Value"
decLength = Len(strMyString)
</pre>
It is importsant to understand that a String variable is really an object which has properties and methods like any other object. One such method is the ''Length()'' method which can also be used to obtain the length of a string variable:
<pre>
Dim decLength As Decimal
Dim strMyString As String = "This is a String Variable Value"
decLength = strMyString.Length()
</pre>