VBScript Split Function
The VBScript Split function takes a string and returns it in an array broken up by the delimiter of your choosing. The basic usage is: somearray = split(expression), where expression is the string you need to parse. Since split defaults to using a blank space as a delimiter, in its basic form you could use split to divide a sentence into individual words. Note that somearray lacks parentheses both when calling the function and when declaring the variable. It is by its nature a one-dimensional array with a number of elements equal to the number of items return from the parse.
Here is a sample which splits a sentence into individual words and then echoes them back in a message box just to verify that the parse took place. Also, to format the output a little and further confirm that each word became a separate variable, I used the constant vbCRLF to add a carriage return / line feed between each word in the echo. (The CR LF in text files is usually inserted by the user hitting the "enter" key. If you are typing in Notepad and hit "enter," the invisible two characters generated put a hard break to your line and wrap you around to the next.)
You can run this sample yourself by pasting the above code into Windows Notepad and saving the file with a *.vbs extenstion (i.e. sample.vbs).
If you do run the sample you'll notice that the last word parsed still has a period attached. Had this been a real world coding problem we would certainly have to deal with that period - but for now we'll just let it ride.
The full syntax for split is: Split(expression[,delimiter[,count[,compare]]])
You can use the optional delimiter parameter to specify a delimiter other than a blank space. One of the most common delimiters would be a comma, as used in the ubiquitous comma separated value (csv) format. Such csv files are flat file databases in which fields are separated by commas and records are separated by carriage return / line feeds.
While it's not exactly a csv parser, in the following example I use split to parse a line of text delimited by commas rather than blank spaces.
The only coding difference between the first and second examples is the addition of the delimiter parameter "," .
The remaining optional parameters are count and compare. Count returns the number of substrings to be returned. The default of -1 returns every substring. Compare gives you the option of doing either a binary or case-insensitive textual comparison. In short, if you want "ABC" to be equal to "abc" then use 1, if you want "ABC" and "abc" not to be equal then use 0.
See more from Web Design
Other Pages You Might Enjoy...
The Meissen Porcelain Manufactory
For more than 300 years the Meissen Porcelain Manufactory has been a central figure in European porcelain. It was at Meissen that the first true hard-paste porcelain was manufactured outside of China, and the story of that accomplishment has the high drama of fiction - all the more intriguing because it is true.
Pirated Glassware that Collectors Want to Own
The 1996 discovery of what is believed to be the wreckage of Blackbeardís ship Queen Anneís Revenge, is providing historians and collectors new information about the fragile and transparent objects that came onto the North American Continent before arrival of the first piece of cut glass.
Collecting Antique Furniture
Of all the collectible antiques, the broad category of furniture is perhaps the most widely held and most satisfying. Frequently handed down through generations, the various chairs, tables, cabinets and other pieces are often in use, adding character and constancy to our daily lives. This guide includes an overview of the significant styles and historical periods, and other important information for collectors.
Collecting Antique Clocks and Watches
Information for collectors of antique clocks and watches. Includes a history of clock and watchmaking, an overview of styles, and important terminology.
Collecting Antique Jewelry
Embodying the wealth and treasure of bygone days, the antique jewelry pieces available today include some of the world's most valuable artifacts. Includes a history of jewelry making, an overview of the major historical periods, and a glossary of antique jewelry terminology.
Home of the Do It Yourself Chatterbot Project. Has a ready to go chatterbot shell and full instructions on how to program it.
Tips for Improving Website Navigation
A business often has more than one target audience it wants to reach with its website. Different customers mean different sales appeals and a homepage needs to be able to direct visitor traffic to go to the right places to get information or make a sale.
Choosing the Right Color for Your Web Site
When people build a web site for their business (or hire a web design company to make it for them), not much thought is put into deciding what color their web site will be as most would rather focus on more important tasks like creating content, web site optimization and promotion. Most simply choose the most web-friendly colors, others use their companyís logo as base while some decide to just use their favorite color.
Beginning at the Beginning - File Systems and Plain Text Files
HTML For the Absolute Beginner
The intent of this tutorial is to provide a basic introduction to making web pages for the person who has never studied HTML before. Once one has worked through this material they should be able to create a bare bones HTML file and be ready to move on to learning to build web pages.