Tag Archives: String

Series of Chars

Arrays

Do not be shy about using arrays, they are not hard to use.

   Dim people(2) As String
   people(0) = "John Henry"
   people(1) = "Catherine Weaver"
   MsgBox UBound(people)
   'access the first element in the array
   MsgBox people(0)

The split() function will make arrays to play with. For this example we are going to use split(string) and split(string, delimiter). The function returns an array of strings or string if it can not find the delimiter.

Dim myarray() as string
Dim mytext as string
Mytext = "the big red dog sat on the hill"
Myarray = split(mytext)
Dim index as integer
Index = 0
Dim output as string
Output = ""
For index to ubound(Myarray) -1
   Output = output & "index:" & index & " " & myarray(index)
Next index
Msgbox output

 

String – Functions

Some examples for common functions.

length of a string “Len()”

dim mystring as String
mystring = "Hello World"
msgbox Len(mystring)

len

Next “Left()” and “Right()” using the “Hello World”

msgbox Left(mystring, 5)

left

msgbox Right(mystring, 5)

Right
There pretty easy, but there is also the “Mid(String, Integer)” and “Mid(String, Integer, Integer)”

MsgBox Mid(mystring, 5)

mid-5

MsgBox Mid(mystring, 2, 5)

mid-2.5
These are just a few check the Microsoft page out for more.

String – Introduction

The Basics
If you have completed a hello word example then you have seen a string.  You can do many interesting things with strings but lets start with the basics.
To declare a string and set its value

dim myfirst as string
myfirst = "abc123"

Join 2 string together

dim mysecond as string
mysecond = "efg123"
msgbox myfirst & " " & mysecond

Remember to place the code in a sub routine. Here is the code below

Sub stringcombine()
   Dim myfirststring As String
   myfirst = "abc123"
   Dim mysecond As String
   mysecond = "efg123"
   MsgBox myfirst & " " & mysecond
End Sub

String Basics
String Basics