This tutorial will teach you all of the basic string functions available in ASP using VBScript. I will keep things concise as possible. The following is a list of the functions and an example of each.
Asc();
Asc() will provide you with the ASCII character code of the character in the parentheses.
| <% str1 = Asc("B") response.write str1 %> |
cStr();
cSrt() will convert a numeric value into a string.
| <% int1 = 35 str1 = cStr(int1) %> |
inStr();
inStr() will locate the occurance of a character (or set of characters) in a string and output it's place.
| <% str1 = "ABCDEF" str2 = inStr(str1,"BC") response.write str2 %> |
LCase();
LCase() will convert an entire string to lowercase.
| <% str1 = "ABCDEF" str2 = LCase(str1) response.write str2 %> |
UCase();
UCase() will convert an entire string to uppercase.
| <% str1 = "abcdef" str2 = UCase(str1) response.write str2 %> |
Trim();
Trim will remove all blank spaces from the beginning or end of a string.
| <% str1 = " ABCDEF" str2 = Trim(str1) response.write str2 %> |
Len();
Len() will tell you the number of characters in a string.
| <% str1 = "ABCDEF" str2 = Len(str1) response.write str2 %> |
Replace();
Replace() will replace a character (or set of characters) with another character (or set of characters).
| <% str1 = "ABCDEF" str2 = Replace(str1,"CD","YZ") response.write str2 %> |
Split();
Split() will split a string into an array of values based on the character defined.
| <% str1 = "ABC,DEF" str2 = Split(str1,",") response.write str2(0) response.write " "response.write str2(1) %> |
Left();
Left() will retrieve the number of characters specified from the left of the string.
| <% str1 = "ABCDEF" str2 = Left(str1,3) response.write str2 %> |
Right();
Right() will retrieve the number of characters specified from the right of the string.
| <% str1 = "ABCDEF" str2 = Right(str1,3) response.write str2 %> |
Mid();
Mid() will retrieve the number of characters specified from the middle of the string.
| <% str1 = "ABCDEF" str2 = Mid(str1,3,2) response.write str2 %> |
That's it! Have fun playing with strings.
Related Articles
- Declaring Variables and FunctionsNow its time to get into some really fun stuff. Yes, variables and functions. Dont worry, its not as bad as it sounds.....lets start with declaring variables. Youll want to keep all of your variables in the HEAD section for now. Place the declarations between the SCRIPT tags inside the
- Easy Flat File Hit CounterCreate a very simple hit pageview counter without any database! Use flat file scripting to make an easy counter!
- Beginner JS Pt. 2This tutorial is a well laid out recipe for basic Javascript. The article is brief and is limited to three topics: Calling the Script, Writing Comments, and Doing Stuff (Basic). Illustrations make it easy.
- Some PHP Functions You Must KnowPHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.
- PHP FunctionsGo to the next level in PHP
- Introduction to SerializingAlso includes an example that you can use to start building apps with serialize.
- JavaScript PromptsWell, lets say you wanted to get somebodys name before they saw the page, and then write their name on your page right before their very eyes... Well, you can do this using a javascript prompt. Heres the command:
- Regular ExpressionsRegular expressions provide a means for advanced string matching and manipulation. They are very often not a pretty thing to look at. For instance:
- Database Connection StringsAlthough our ASP database tutorials all use MS Access connection strings, there are many sorts of database software out there for use with ASP. This tutorial will show you how to connect with them...
- Random Password GenerationWeb programmers will enjoy this article. It is a quick and effective way to create Random Password Generation - needed for security and anti-spam measures. The author provides concise lines of code, screenshots and simply read texts.
