Applying a UCase (all uppercase) or LCase (all lowercase) to a word or sentence is a standard function within Dreamweaver. Applying a UCase to the first letter and the rest a LCase in the word or sentence needs some manual coding. This short tutorial shows you how to use these stringfunctions.
Let's say we have a record in our database that along other things holds the heading/name of our webpage. This name is used in a DHTML menu, but also used as the name on top of the webpage.
As i wanted to display the name in the DHTML menu as all LCase (lowercase) for readibility (i think this looks nicer) and at the top of the page i wanted to make the first letter UCase (uppercase), but i didn't want to create two fields in my database that holds the LCase and UCase name. So i created one field and added the name as LCase (for example: introduction, products, service).
This solved my problem for the DHTML menu, but not for the top headings of my webpage. This is where we handcode our database field in our webpage.
Let's say i have dragged & dropped the following databasefield into my webpage to show:
<%=(rsExample.Fields.Item("heading").Value)%>
First i will apply the stringfunction UCase to convert the first character. I will start counting from the left and have to determine the first position:
UCase(Left((rsExample.Fields.Item("heading").Value),1))
This will return the first character as an uppercase character.
Next i will apply the stringfunction LCase to the rest of the databasefield(string). I will start from the right and use the stringfunction LEN to get the total length of the field and will need to leave out the first character:
LCase(Right(((rsExample.Fields.Item("heading").Value)), Len((rsExample.Fields.Item("heading").Value))-1))
This will return everything in lowercase after the first position.
Now all that is left, is to put these 2 conversions togehter:
<%=UCase(Left((rsExample.Fields.Item("heading").Value),1)) & LCase(Right(((rsExample.Fields.Item("heading").Value)), Len((rsExample.Fields.Item("heading").Value))-1))%>
That's it.
Knowing this you can do a lot of string conversions. Just experiment and see what the result is of your conversion.
UCase:
Converts a string to uppercase
LCase:
Converts a string to lowercase
Left:
Extracts a certain number of characters, starting at the left of the string
Right:
Extracts a certain number of characters, starting at the right of the string
Len:
Determines the length of a string
Next time i will show you an example on how to use the stringfunctions REPLACE and MID.
Comments
Be the first to write a comment
You must me logged in to write a comment.