Split ASP String Function
Are you trying to break a string up into smaller pieces? ASP provides an easy to use split function which lets you dice and slice a string.
Let's say you take in a sentence and want to put each word into a different variable. So you take in
NameStr = "Mr. John Smith"
Set up the array to hold the results with
then do the split, using a space as the split indicator
WordArray = Split(NameStr, " ")
Now WordArray(0) is equal to "Mr.", WordArray(1) is equal to "John" and WordArray(2) is equal to "Smith"! You can use various array functions and other string functions to work with these results.
There's of course a wealth of ways to use the split function. Many export programs will separate out their fields by a pipe symbol. A pipe is the vertical up-and-down line like this:
So you could do a split function looking for that pipe to break them out into their component pieces.
Be cautious that the field you're using to split really is only used for that split functionality. For example, you might think using a comma as a separator field is a wonderful idea. But what happens if there's actually a comma in one of the fields? Something like this:
In that fourth row the man has a title after his last name, so he has his last name entered as
But the split operation will see that comma and think it's a separator field.
That's why it's usually best to use a separator of a pipe (|) or something else quite unusual, so that you're sure it won't be showing up in the actual data stream as a normal value.
If you're working with strings be sure to look through the other ASP String Functions to learn how they work!
Still stuck? Please be sure to Contact Lisa Shea - that's me - and I'm happy to lend a hand. I've been programming in ASP classic for many, many years and can help you get through your coding challenge quickly and easily!
To have an easy to use, easy to read reference on hand as you code, also check out my Intro to ASP Book which comes in both ebook and paperback format.
Thanks for stopping in to my page - and good luck!
ASP String Functions