Work with Text

Working with text is probably just as common as working with numbers in most programs. Visual Basic refers to text data as strings and it provides a set of string operators and functions just as it does for math. Since strings and numbers are very different types of data, the nature of operators and functions are very different, as shown by Tables 3-7 and 3-8.

Table 3-7. Visual Basic string operators

& (join)

Like (compare)

= (assign)

Table 3-8. Visual Basic string functions

Task

Function

Use to

Compare

Option Compare

Change the string comparison rules

 

Instr

Find one string inside of another

 

StrComp

Compare one string to another

Convert

Asc

Convert a character to its numeric ANSI value

 

Chr

Convert a numeric ANSI value to a character

 

Format

Convert a number or a date to a string using a specific format

 

LCase

Make a string lowercase

 

UCase

Make a string uppercase

 

StrConv

Change the capitalization, locale, or encoding of a string

 

Val

Get the numeric value of a string

Arrays

Split

Convert a string to a one-dimensional array

 

Join

Convert a one-dimensional array to a string

Change

Left

Get a number of characters from the left side of the string

 

Len

Get the length of a string

 

LTrim

Remove spaces from the left side of a string

 

LSet

Copy one string to another, left-aligning the result

 

Mid

Get a specified number of characters from within as string

 

Replace

Search ...

Get Programming Excel with VBA and .NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.