What is the syntax to return a substring?

To return a substring that does not start with the beginning of the string: click me
To return a substring that starts with the beginning of the string: click me
To return a substring that does not start with the beginning of the string: click me

Advertisements

What is the syntax to split a string from the middle?

Mid (String, start, length)
'String - string from which return value is extracted; mandatory parameter
'start - integer of starting position of extraction; mandatory parameter
'length - length of extraction; optional
'examples
Dim sentence As String
sentence = "blackgraywhite"
MsgBox (Mid(sentence, 6, 4)) 'gray
MsgBox (Mid(sentence, 1, 5)) 'black
MsgBox (Mid(sentence, 10)) 'white

 

What is the syntax to split a string from the right?

Right(String, Length)
‘string – string to be searched; mandatory parameter
‘length – integer specifying the number of characters to be returned; mandatory parameter
'examples
Dim name As String
name = "Elon Gates"
MsgBox (Right(name, 5)) 'Gates
MsgBox (Right(name, 8)) 'on Gates
MsgBox (Right(name, 10)) 'Elon Gates

 

What is the syntax to split a string from the left?

Left(String, Length)
‘string – string to be searched; mandatory parameter
‘length – integer specifying the number of characters to be returned; mandatory parameter
'examples
Dim name As String
name = "Bill Jobs"
MsgBox (Left(name, 4)) 'returns Bill
MsgBox (Left(name, 7)) 'returns Bill Jo
MsgBox (Left(name, 9)) 'returns Bill Jobs

 

 

What is the syntax to split an array based on a value?

Split(expression, delimiter, count, compare)
'expression is a string; only mandatory parameter
'count - how many substrings to be returned. -1 means all substrings are returned
'compare - 0 for binary, 1 for textual

'be aware that the Split function returns an array value, not string value.
‘example – splits the array based on the delimiter “#”
Dim myArray As Variant
Dim size As Integer

myArray = Split("Regular#Regular#Vegetarian#Regular#Vegan", "#")
size = UBound(myArray)

For i = 0 To size
    MsgBox ("Guest " & i & "'s meal option is: " & myArray (i))
Next i

unnamed (2).jpg