String operations – Sub strings and Concatenation

We looked at what a string variable was last week e.g. “James”, “Eh12”. You need to know about two things that you can do to this type of data:

Substring – take a part of a string e.g. take “ame” from “James”

Concatenation – join two strings together e.g. join “Craig” and “mount” to make “Craigmount”

That is pretty much it, except you need to know how to make Visual Basic do this. Here are some examples:

Concatenation is done using the & symbol.

For example:

first = “j”

second = “whiteside”

username = first & second

The code above will make username equal to “jwhiteside“.

Substrings are done by using left, mid (or right).

For example:

day = “wednesday”

firstbit = left(day, 6)

middlebit = mid(day, 4, 3)

lastbit = right(day, 3)

This would make firstbit equal to “Wednes”, secondbit equal to “nes” and lastbit equal to “day”.

Click on the notes below to see the other examples and the questions again.

string-ops.jpgstring-op-questions.jpg

Advertisements

Tags:

One Response to “String operations – Sub strings and Concatenation”

  1. Abby Says:

    The new updated blog looks good

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: