What is the syntax to count how many times a substring occurs in a string?

<integer variable> = Len(<string>) - Len(Replace(<string>, "<substring>", "")) 
'example
sentence = "Hello, this is a sentence,"
countCommas = Len(sentence) - Len(Replace(sentence, ",", "")) 
msgbox(countCommas) 'output is 2
Advertisements

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

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