October 20, 2016
Hot Topics:

String Functions Explained

  • November 19, 2002
  • By John Percival
  • Send Email »
  • More Articles »

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 
   succeeded1 = False
End If

If UCase$(PasswordAttempt) = UCase$(ActualPassword) _
   Then succeeded2 = True 
   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.


Mid(string, start[, length])


This function returns a string of repeating characters. For example, String$(20, "*"), would return "********************".


String(number, character)


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)

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

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

Sitemap | Contact Us

Thanks for your registration, follow us on our social networks to keep up-to-date
Rocket Fuel