What is the syntax to change text case?

UCase(<value to be converted to upper case>)
LCase(<value to be converted to lower case>)
‘examples
MsgBox( LCase(“HELLO”)) ‘returns hello
Range (“A1”) = UCase(Range(“A1”))
Advertisements

What is the syntax to return a word mid-sentence?

Mid (str, start, length)
‘str – string/sentence; mandatory parameter
‘start – starting position to return characters; mandatory parameter
‘length – number of characters to return; optional parameter
‘example
Mid(“The dog jumps”, 5, 3) ‘returns “dog”

What is the syntax to return string a certain number of times?

String(number, character)
‘number – number of times value will be returned; mandatory parameter
‘character – character value that will be repeated; mandatory parameter
‘examples
Dim name As String
name = "Steve Musk!"
MsgBox (String(1, "S")) 'S
MsgBox (String(20, "!")) '!!!!!!!!!!!!!!!!!!!!
MsgBox (String(5, "M")) 'MMMMM

 

What is the syntax to compare strings?

StrComp (string1, string2, compare)
‘both string1, string2 are mandatory parameters
‘compare – 0 for binary comparison or 1 for textual comparison; optional parameter with 0 being default
‘please note, an integer value is returned

‘If str1 < str2 then -1
'If str1 > str2 then 1
'If str1 = str2 then 0
‘examples
MsgBox (StrComp("Hello", "Hello")) '0
MsgBox (StrComp("hello", "HELLO")) '1
MsgBox (StrComp("HELLO", "hello")) '-1
MsgBox (StrComp("Hello", "Goodbye")) '-1

 

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