VB and VBA Users Source Code: Returning an item from a deliminated string
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Returning an item from a deliminated string
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Wednesday, November 20, 2002
Hits:
866
Category:
Visual Basic General
Article:
Below is a useful function for returning an item from deliminated string. 'Purpose : Returns a portion of a deliminated string 'Inputs : sDelimString The deliminated string to return a portion of. ' sDelim The string deliminator. ' lItemIndex The index of the item to return. ' [sDefault] The value to return if the index is not found 'Outputs : Returns the request portion of the deliminated string ' Returns an empty file name on error. 'Author : Andrew Baker 'Date : 13/11/2000 10:14 'Example : Debug.Print StringItem("Andrew|Is|Ace","|",3) ' Returns "Ace" 'Notes : 'Revisions : Function StringItem(sDelimString As String, sDelim As String, ByVal lItemIndex As Long, Optional sDefault As String = "") As String Dim asItems() As String, lUbound As Long asItems = Split(sDelimString, sDelim) lUbound = UBound(asItems) lItemIndex = lItemIndex - 1 If lUbound >= lItemIndex Then StringItem = asItems(lItemIndex) Else StringItem = sDefault End If End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder