[bb] Delimeted string handler by Rob Farley [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:38

Previous topic - Next topic

BlitzBot

Title : Delimeted string handler
Author : Rob Farley
Posted : 1+ years ago

Description : OK,

You've got a string with a few items in it and you want to find the 5th one. This function does it for you.

entry(5,"Mr,Mrs,Dr,Ms,Miss",",") will return "Miss"

Usage

Entry ( [element number], [list$] , [Delimeter$] )


Code :
Code (blitzbasic) Select
; Entry function by Rob Farley 2004
; rob@mentalillusion.co.uk

Function Entry$(number,list$,delimeter$)

n=1
count = 1
found = False
start = 1

If number > 1
Repeat
If Mid(list,n,1)=delimeter
count = count + 1
If count = number
found=True
start = n + 1
Exit
EndIf
EndIf
n=n+1
Until n >= Len(list)
If found = False Then RuntimeError("List Element out of Range")
EndIf

Endof = Instr(list,delimeter,start)
If endof = 0 Then endof = Len(list)+1

Return Mid(list,start,endof-start)

End Function


Comments :


Damien Sturdy(Posted 1+ years ago)

 Neato function there :D useful!


aab(Posted 1+ years ago)

 excellent


_PJ_(Posted 1+ years ago)

 Helped me out a lot! Cheers!