String Functions Explained
Use these two functions to convert a string to entirely upper case or entirely lower case characters. This is very useful if you want to do a case insensitive search, or if a password is not case sensitive. For example:
MyString = "This is a nice long string" UCaseString = UCase$(MyString) LCaseString = LCase$(MyString)
UCaseString contains "THIS IS A NICE LONG STRING", and LCaseString contains "this is a nice long string". This can be used practically:
PasswordAttempt = "MyPaSs" ActualPassword = "mYpAsS"If PasswordAttempt = _ ActualPassword Then succeeded1 = True Else succeeded1 = False End If If UCase$(PasswordAttempt) = UCase$(ActualPassword) _ Then succeeded2 = True Else succeeded2 = False End If
Mid(string, start[, length])
This function returns a string of repeating characters. For example, String$(20, "*"), would return "********************".
This function returns the length of a string. It is useful in a For...Next loop to do something to each character in a string. For example:
mystring = "Hello world!" mylen = Len(mystring) For charnum = 1 To mylen Debug.Print Mid$(mystring, charnum, 1) Next
Here you will get H, e, l, l, o, , w, o, r, l, d, !, printed out in the debug widow, with each character on a separate line. mylen returns 11 because the length of the string is 11.
Watch out soon for advanced string functions, where we will show you how to do search and replace facilities, and look at the other string functions.
Page 2 of 2