String Functions Explained
UCase$, LCase$
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
In this case, succeeded1 would be False, and suceeded2 would be True. This is because the two actual passwords do not equal each other, but when they are both converted into upper case, they do equal each other.
Syntax
Mid(string, start[, length])
String$
This function returns a string of repeating characters. For example, String$(20, "*"), would return "********************".
Syntax
String(number, character)
Len
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.
Syntax
Len(string)
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
This article was originally published on November 20, 2002