Author Topic: VB style Split function with field limiting.  (Read 1052 times)

briansykes

  • Newbie
  • *
  • Posts: 23
VB style Split function with field limiting.
« on: October 05, 2009, 08:15:57 AM »
Alright i posted one before and it didn't work exactly the way i wanted it to so i recoded it and made a much better way without using Replace.  It need's two functions to work,

Code: [Select]
PUBLIC FUNCTION NthField(s AS String, delimiter AS String, field AS Integer) AS String
  
  DIM t1 AS String[]
  DIM i AS Integer
  t1 = Split(s, delimiter)
  RETURN t1[field]
  
END

PUBLIC FUNCTION VBSplit(s AS String, delim AS String, numfields AS Integer) AS String[]
  DIM arr AS String[]
  DIM t AS String
  DIM i AS Integer
  arr = NEW String[]
  FOR i = 0 TO numfields - 1
    arr.Add(NthField(s, delim, i))
  NEXT
  t = arr.Join(delim)
  arr.Add(Mid(s, Len(t) + 1))
  RETURN arr
END
« Last Edit: October 05, 2009, 08:47:31 AM by briansykes »

Linux Basic

VB style Split function with field limiting.
« on: October 05, 2009, 08:15:57 AM »