A string consists of an array of encoded characecters
To create a string in visual basic use
Dim myString As String
To asign it a value use
MyString = "Hello Worrld!!"
Strings can also be used in logical operations
If enteredPassword = "Password123" Then
MsgBox("Welcome admin, your instruction is my command")
These are a few functions that you can preform to manipulate or extract data from
- ToUpper()
- Trim()
- ToLower()
- Length()
- Contains()
- EndsWith()
- Insert()
- ToCharArray()
- Split()
- Substring()
The Trim function will remove any blank spaces from around inputed text.
Dim myCatsName As String
MyCatsName = "kitkat "
MyCatsName = MyCatsName.Trim
When displayed the variable MyCatsName would output as
kitkat
A char is a single encoded charecter
Dim faveChar As Char
favChar = 'N'
A string is just an array of chars
To find out how many chars there are in a string use
Dim myString As String = "James"
MsgBox("There are " & myString.Length & "chars in this string")
Chars is a method of the String variable type. It can be used to find the lengh of any string.
Chars is a function that can extract a charecter from a string
MyString = "It's not wise to upset a Wookiee"
OneLetter = MyString.Chars(18)
This should return the letter 'p'
If you need to know if a string conains a certain charecter