VBScript: Functioning with Strings - Uppercase and Lowercase
(Page 4 of 4 )
We use LCase() and UCase() to make a string lower case or upper case, respectively. Here is the LCase function at work:
<html>
<body>
<script type="text/vbscript">
dim small
small="LOOK HOW BIG I AM!"
document.write(LCase(small))
</script>
</body>
</html>
Even though the value in the variable “small” starts out fully capitalized, the result is:
Look how big I am!
You will note that you do not have to use a variable in order to use the LCase() function:
<html>
<body>
<script type="text/vbscript">
document.write(LCase("I AM A GIANT!"))
</script>
</body>
</html>
This prints out:
i am a giant!
The UCase() works in a similar fashion, only it makes everything upper case:
<html>
<body>
<script type="text/vbscript">
document.write(UCase("I am a giant!"))
</script>
</body>
</html>
The result:
I AM A GIANT!
If it sees that a letter is already upper case, it does not change it.
You can also use UCase() on variables as well:
<html>
<body>
<script type="text/vbscript">
dim giant
giant="i am a giant!"
document.write(UCase(giant))
</script>
</body>
</html>
Again we have:
I AM A GIANT!
And finally, we can also mix the UCase() and LCase() together, like this:
<html>
<body>
<script type="text/vbscript">
dim giant
giant="i am a giant!"
document.write(UCase(giant)) & "<br />"
document.write(LCase(giant))
</script>
</body>
</html>
This will print out:
I AM A GIANT!
i am a giant!
One last thing on the UCase and LCase functions: you will note that the actual value of the object you use the functions on does not change. Observe this example:
<html>
<body>
<script type="text/vbscript">
dim giant
giant="i AM a giant!"
document.write(UCase(giant)) & "<br />"
document.write(LCase(giant)) & "<br />"
document.write(giant)
</script>
</body>
</html>
The print out is:
I AM A GIANT!
i am a giant!
i AM a giant!
As you can see, we printed out the value in “giant” to show that it remains unchanged, despite using the functions on it.
Conclusion
There are sixteen built-in functions for dealing with strings in VBScript and we have only touched upon four of them in this article. In the next tutorial we will cover more, if not all, of them. And in the weeks to come, we'll eventually conclude our discussion of functions altogether. So be sure to check back often.
Till then…
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |