String operations – Sub strings and Concatenation

By mrwhiteside

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

Tags:

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

  1. Abby Says:

    The new updated blog looks good

Leave a Reply