O'Reilly logo

Programming Excel with VBA and .NET by Steve Saunders, Jeff Webb

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required