Home | Advertising Info73 USERS CURRENTLY ONLINE   
PowerASP

Try aspprotect for FREE !!
the premier asp based user management system !!

   Site Search Contact Us Sunday, March 14, 2010  


TLsplit Function





This function was designed by my Co-worker Tim Lasek after I asked him to make it because of things that I didn't like about the built in vbscript function called "split". I primarily use it to take arrays passed from the HTTP HEADER and put them back together, but Tim decided to enhance it by letting you specify the delimiter and by having the array dynamically declare itself so that it is always the exact size it needs to be. This makes this function very versatile. This also handle null values better than split does and overall I like it better..

Function
TLsplit(StrToSplit, Delim)

Usage:  TestArray = TLsplit("This,is,a,dynamic,split,function", ",")

Result:
TestArray(0) = 6
TestArray(1) = This
TestArray(2) = is
TestArray(3) = a
TestArray(4) = dynamic
TestArray(5) = split
TestArray(6) = function

No need to Dim() the array before calling the function.
Array(0) = Number of elements in the array.
If StrToSplit = NULL Then Array(0) = 0.
Checks for Delim not found.
Don't use " for Delim.

Below is the Function Source Code and Example Usage Code

<%
Function TLsplit(StrToSplit,Delim)
Dim StrArray()
If StrToSplit = "" Then
  ReDim StrArray(1)
  StrArray(0) = 0
  StrArray(1) = ""
  TLsplit = StrArray
Else
  dcount = 0
  For TLsI = 1 To Len(StrToSplit)
   If Mid(StrToSplit,TLsI,1) = Delim Then dCount = dCount + 1
  Next
  If dCount = 0 Then
   ReDim StrArray(1)
   StrArray(0) = 1
   StrArray(1) = StrToSplit
   TLsplit = StrArray
  Else
   ReDim StrArray(dCount + 1)
   StrArray(0) = dCount + 1
   TempArray = Split(StrToSplit,Delim)
   For TLsI = 1 To dCount + 1
    StrArray(TLsI) = Trim(TempArray(TLsI - 1))
TLsplit = StrArray
   Next
  End If
End If
End Function
%>

<% RandomVariable = "This,is,a,dynamic,split,function" %>

<%
TestArray = TLsplit(RandomVariable, ",")
For I = 1 To TestArray(0)
Response.Write("TestArray(" & I & ") = " & TestArray(I) & "<br>")
Next
%>

 

   Active Server Pages Rule The World
Contact Us  

download aspbanner !!
rotate banners on your website !!

All artwork, design & content contained in this site are Copyright © 1998 - 2010 PowerASP.com and Christopher J. Williams
Banner ads ,other site logos, etc are copyright of their respective companies.
STATS Unless otherwise noted - All Rights Reserved.

Active Server Pages ASP ASP.NET .aspx .ascx Web HTML Developer Internet Microsoft Web Services Visual Studio .NET CJWSoft ASPProtect ASPBanner ASPClassifieds www.aspclassifieds.com, www.powerasp.com,www.cjwsoft.com,www.aspphotogallery.com,www.codewanker.com,www.aspprotect.com,www.aspbanner.com