What is the syntax to fill a string with spaces?

Space(number)
‘number is number of spaces
'example
MsgBox ("First" & Space(2) & "Second" & Space(20) & "Last")

unnamed (5).jpg

 

 

Advertisements

What is the syntax to replace a string with another?

Replace(String, find, replacewith, start, count, compare)
'string - string that will be searched; mandatory parameter
'find - string part that will be replaced; mandatory parameter
'replacewith - string part that will be inserted; mandatory parameter
'start – integer specifying the starting position of search; optional parameter where default is 1
'count - integer specifying number of times the replacement has to be performed; optional parameter
'compare - integer specifying the comparison method: 0 for binary, 1 for textual; optional parameter
'examples
Dim sentence As String
sentence = "The red fox"
MsgBox (Replace(sentence, "red", "blue", 1, 1)) 'The blue fox
MsgBox (Replace(sentence, "fox", "panda", 1)) 'The red panda
MsgBox (Replace(sentence, "fox", "panda", 9)) 'panda
MsgBox (Replace(sentence, "The", "My")) 'My red fox

 

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 return the index of a string found within another string?

InStr (start integer, string1, string2, compare)
‘start integer – specifies starting position for search; optional parameter
‘string1 – string to be searched; mandatory parameter
‘string2 – indicate string value; mandatory parameter
‘compare - sets string comparison between 0 for binary comparison (default) or 1 for text comparison; optional
'example
Dim name As String
name = "Steve Gates"
MsgBox (InStr(1, name, "S")) 'returns 1
MsgBox (InStr(7, name, "hello")) 'returns 0
MsgBox (InStr(1, name, "Gates")) 'returns 7
MsgBox (InStr(name, "Steve")) 'returns 1

Be aware: spaces count as a character, a string’s index starts at 1, and a 0 yield means the string is not contained. The search occurs from left->right. For a right->left search, use InStrRev.