Modifying String Case

Microsoft® Windows® 2000 Scripting Guide

Font control is not a strong point of VBScript. Regardless of whether you are displaying output in the command window or in a message box, you have no ability to control such font characteristics as style, size, and color. In fact, about the only thing you can do with fonts is modify the case; that is, you can configure a character (or set of characters) to be either uppercase or lowercase.

Modifying string case can be useful in displaying information. By changing case as needed, you can either ensure a consistent look to a data display (for example, all items shown in lowercase letters) or, alternatively, draw attention to specific items. For example, in this hypothetical output it is easy to see which server requires immediate attention:

Server          Status
atl-dc-01      Healthy
atl-dc-02      Healthy
ATL-DC-03      ERROR
atl-dc-04      Healthy

Modifying the case is also useful for data entry. For example, to ensure that users enter states using an all-uppercase format (WA, OR, CA), you can simply take the value they enter, regardless of case, and convert it to all uppercase letters.

The two functions that allow you to modify string case are described in Table 2.15.

Table 2.15 Functions for Modifying String Case

Function

Description

LCase

Converts all the alphabetic characters in a string to their lowercase equivalents.

The following lines of code convert the string Arlene Huff to the all-lowercase string arlene huff.

UserName = "Arlene Huff"
Wscript.Echo LCase(UserName)

UCase

Converts all the alphabetic characters in a string to their uppercase equivalents.

The following lines of code convert the string Arlene Huff to the all-uppercase string ARLENE HUFF.

UserName = "Arlene Huff" Wscript.Echo UCase(UserName)