Utilizing The Split Function

By ServerWatch Staff (Send Email)
Posted Aug 9, 1999


Watkins

corner.jpg (739 bytes) Utilizing The Split Function corner2.jpg (786 bytes)

See this script in action: click here

If your site allows users to input information for processing or storage, then you most likely know what a pain it is to write out and organize those pages. Taking into possibly all errors that can occur and everything in between. This is more of a mess if you have to take a lot of information or even have to mess with different types of information. Though I don't have a solution for all of that, I do for part of it.

If your site allows users to input information for processing or storage, then you most likely know what a pain it is to write out and organize those pages. Taking into possibly all errors that can occur and everything in between. This is more of a mess if you have to take a lot of information or even have to mess with different types of information. Though I don't have a solution for all of that, I do for part of it.

If you need a quick, easy way to collect like information from a user, then the Split Function is your ticket. If you've ever entered stock quotes at a website and had to seperate them by a comma or another type of delimiter and wondered how they did that, then here is your answer.

I'm going to use for an example what I see as the most widely used application of this function, stock quote look-ups. Lets say your designing your site so that users can look up stock quotes. Most people own shares in more than one company so you should give them the option of looking up more than one at a time. To save space on your page you can't simply put 10 text boxes on the page for 10 different quotes, and you can't limit users to just one quote per form submission, but what you can do is let users enter quotes in one text box using delimiters and later on your form processing page serperate the quotes and process them how ever you want to. Here's how you do it!!

Your form page. It is no more than that. 1 Text box is all it takes.

<form method="post" action="SplitString.asp">
<input type="text" name="stockquotes">
<input type="submit" value="Get Quotes">
</form>

SplitString.asp. This is the interesting part. We will now seperate the string into individual quotes.

<%
Dim strStockQuotes
Dim araStockQuotes
Dim intElements
Dim i
Dim strStockQuote

strStockQuotes = request("stockquotes")
' This is the input from the form.
araStockQuotes = split(strStockQuotes, ",")
' We have just created an array. Note: inside the function I used "," - This is the
' Delimiter that I'm using. eg. if the string was "1, 2, 3" the function would return
' an array that contained "1" "2" and "3". If your string was "1 2 3" and your
' delimiter was a space (" ") , then your array would would contain: "1" "2" and
' "3"


intElements = ubound(araStockQuotes)
' Get the number of elements.

For i = 0 to intElements
     strStockQuote = araStockQuotes(i)
    
'here you process the individual stock quote however you need to.
      response.write strStockQuote & "<br>"
Next
%>

Page 1 of 2


Comment and Contribute

Your name/nickname

Your email

(Maximum characters: 1200). You have characters left.