String functions

VBScript provides a rich library of built-in functions to deal with strings. With string functions, you can manipulate strings; for example, you can retrieve or change part of a string. Although all the functions we'll discuss may seem overwhelming at first, they are quite easy to use and remember once you try them a couple of times.

Test here LCase ()!
Enter some text below to see what LCase () will return.
Text:
 

The LCase (string) returns string with all all its uppercase letters converted to lowercase letters. For instance, LCase ("String Functions In Asp Are Easy To Use.") will return: string functions in asp are easy to use. If the string contains special characters or numbers, those characters are unaffected by the LCase function. Also, string function names are not case sensitive in VBScript so you can use either all lowercase or uppercase letters or even a combination thereof when invoking a function. The following are some of legitimate ways of calling the LCase (string) function: Lcase (string), lcase (string), etc.

Test here UCase ()!
Enter some text below to see what UCase () will return.
Text:
 

Similarly, UCase (string) function returns a string with all its lowercase letters converted to uppercase letters. As with the LCase () function, non-alphabetical characters are not changed by the Ucase () function. For instance, UCase ("2nd string function") will return 2ND STRING FUNCTION.

LTrim (string) removes all space characters from the left side of string. For instance, LTrim ("      LTrim (string) function removes all spaces from the left side of a string  ") will return LTrim (string) function removes all spaces from the left side of a string  . Notice that LTrim (string) preserves spaces on the right side of the string.

Similar to LTrim () is the RTrim (string) function. What do you think RTrim () does? Well, RTrim () removes all space characters from the right side of a string. For example, RTrim ("      RTrim (string) function removes all spaces from the right side of a string  ") returns      RTrim (string) function removes all spaces from the right side of a string. Notice that RTrim (string) preserves spaces on the left side of the string. So what do you do if you want to removes spaces from the both side of a string? Well, you could first remove the spaces on the left of a string by calling the LTrim () function and then call the RTrim () function with the result returned from the LTrim () function. There is, however, much more efficient way to remove spaces on both sides of a string.

With Trim (string) function, you can remove space characters from both side of a string. For instance, Trim ("  some text  ") returns just some text. The LTrim (), RTrim (), and Trim () function come in handy when you are requesting input from the user. The user, for instance, may inadvertently or intentionally enter some extra space characters when entering data. To catch any possible space characters surrounding the input, the Trim () function can be used to remove spaces on the left and right sides of the input string.

If you wanted to find out the number of characters in a string, you can use the len(string) function. Len("string functions") will return 16. Note the function also counts space characters present in the string.

The Space (number) returns a string consisting of number of spaces. So space(3) returns "   ". This can be useful for formatting, especially when writing to text files.