Ooops
November 24, 2020, 07:10:38 AM

Author Topic: [bb] Delimeted string handler by Rob Farley [ 1+ years ago ]  (Read 842 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
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
  1. ; Entry function by Rob Farley 2004
  2. ; rob@mentalillusion.co.uk
  3.  
  4. Function Entry$(number,list$,delimeter$)
  5.  
  6. n=1
  7. count = 1
  8. found = False
  9. start = 1
  10.  
  11. If number > 1
  12.         Repeat
  13.                 If Mid(list,n,1)=delimeter
  14.                         count = count + 1
  15.                         If count = number
  16.                                 found=True
  17.                                 start = n + 1
  18.                                 Exit
  19.                         EndIf
  20.                 EndIf
  21.                 n=n+1
  22.         Until n >= Len(list)
  23.         If found = False Then RuntimeError("List Element out of Range")
  24. EndIf
  25.  
  26. Endof = Instr(list,delimeter,start)
  27. If endof = 0 Then endof = Len(list)+1
  28.  
  29. Return Mid(list,start,endof-start)
  30.  
  31. 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!


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal