Discovering Visual Basic .NET: Using Functions and Arguments, Page 3
More Common Functions
This section introduces you to some of the more commonly used functions in VB.NET. You've seen a few of these functions already, but most of them, you haven't.
This summary should give you a good idea of many things VB.NET can help you do. But, keep in mind that this isn't an exhaustive list of functions—not by a long shot. And even with the functions I do list here, I won't bore you with every last detail. If you need more information, you can check out the VB.NET documentation, which comes with the .NET Framework.
Playing with Strings
Len is short for length. When you send a string to this function as an argument, it returns the number of characters in the string.
Here's an example:
Imports System Imports Microsoft.VisualBasic Module StringLength Public Sub Main() Dim MyString As String Dim MyLength As Integer MyString = "Butter side down" MyLength = Len(MyString) Console.WriteLine("This string: " & MyString) Console.WriteLine("Is " & MyLength & " letters long.") End Sub End Module
MyLength is 16—that's how many letters are in the string.
LCase and UCase both take one string as an argument. They both return that same string converted to lower- or uppercase, respectively:
LCase("This Is A Scary Story")
This function would return "this is a scary story".
UCase("This Is A Scary Story")
This function returns "THIS IS A SCARY STORY".
LTrim, RTrim, Trim
The trim functions—LTrim, RTrim, and Trim—each receive a string as an argument and return a string. The string returned is the same as the string sent except that:
- LTrim chops off any spaces that appear on the left side of the string (at the beginning). These are often referred to as leading spaces.
- RTrim chops off any spaces that appear on the right side of the string (at the end). These are often referred to as trailing spaces.
- Trim chops off both leading and trailing spaces.
LTrim(" Hello! ")
This function returns "Hello! ".
RTrim(" Hello! ")
This function returns " Hello!".
Trim(" Hello! ")
This function returns "Hello!".
Page 3 of 5