May 21, 2019
Hot Topics:

Discovering Visual Basic .NET: Using Functions and Arguments

  • December 30, 2004
  • By Bill Hatfield
  • Send Email »
  • More Articles »

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

Strings are letters, words, and numbers that can be stored in a variable. For example, names, addresses, and book titles are stored in the computer as strings. Because strings are so important, many commands and functions exist to deal with them. I describe some of the more important ones here.


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, UCase

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.

For example:

LTrim("      Hello!   ")

This function returns "Hello!   ".

RTrim("      Hello!   ")

This function returns "      Hello!".

Trim("       Hello!   ")

This function returns "Hello!".

Page 3 of 5

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Thanks for your registration, follow us on our social networks to keep up-to-date