The ASP split function is used to - guess what - split a string into specific parts. The resulting number of items is variable and depends on how we use the function.
Basically the split function has the following syntax:
VarArray = split(string, delimiter, numberOfItems)
1) string is the string to be split;
2) delimiter is the element used to determine where to split the string;
3) numberOfItems is optional and limits the number of returned items in the array.
Let's see some examples.
The output of the above code will be:
VarString = "Welcome to The Web Thought!"
VarArray = split(VarString, " ")
For each item in VarArray
response.write(item & "<br>")
If we change the split function and add a limit to the number of items in the array:
the output will be:
split(VarString, " ", 3)
Having said that, the split function might become very useful if we need to store dynamic information in a database and retrieve them storing them in an array. We can, for example, store a list of available colour codes for a specific product, separating them by a semicolon:
The Web Thought!
then we can store the recordset field item in a string and split it using ";" as delimiter:
The output will be:
VarArray = split("A1;A2;A3;A4", ";")
I hope you've found the above information useful for your projects. In the meantime, happy programming!