Field Function cField$

Modified on 2021/10/27 10:59 by CaptainBoing — Categorized as: Arrays, Strings

Here is a good alternative to the SPLIT function. It returns the required element from a delimited string without creating an array.

http://www.thebackshed.com/forum/forum_posts.asp?TID=9766&PN=1

As a CFunction, it is very compact and fast.

Note: CFunctions and CSubs incompatibility. This article does not apply for the MicroMite eXtreme (MMX) and ArmMite platforms.

The delimiter defaults to , and returns an empty string if the ordinal is out of range or the delimiter not found.

'
' File Cfield.bas written 25-Jul-2017 14:32:42
'
' Usage: a$=Cfield$("one,two,three",2,",") or Cfield$("one,two,three",2)
' returns: "two"
' The delimiter character is optional and can be almost any char
' eg "," or ";" or ":" or "/" or "x" or " " ... (default: ",")
'
' It leaves leading and trailing spaces untrimmed
' Please use LTrim & RTrim for that if you need it(CFunctions)
'
' One call of Cfield$() takes about 0,3ms
'
' For the TBS by twofingers (2017), Public Domain
'

CFunction Cfield$(string,integer,string) string
    00000000
    27BDFFD8 AFBF0024 AFB40020 AFB3001C AFB20018 AFB10014 10C00003 AFB00010
    10000002 80C60001 2406002C 90B30000 24900001 90850000 02052821 0080A021
    02008821 10000008 24120001 14660005 26020001 26910001 26520001 325200FF
    0200A021 00408021 12050005 0272102B 5040FFF6 82030000 10000021 3C029D00
    26910001 3C029D00 8C420040 0040F809 24040100 0253902B 16400011 A0400000
    0200A021 1260000F 8FBF0024 02911823 A0430000 0291182B 1460000A 8FBF0024
    00401821 24630001 92240000 A0640000 26310001 0291202B 5080FFFB 24630001
    8FBF0024 8FB40020 8FB3001C 8FB20018 8FB10014 8FB00010 03E00008 27BD0028
    8C420040 0040F809 24040100 1000FFE5 A0400000
End CFunction

See Also
The following is a pure MMBasic solution and thus is compatible with MMX SPLIT Function (VB work-a-like)