Categorie
Sage X3 Tips & Tricks

Split function

Split a string into an array of string
Parameters:
PPSTR: The complete string to split
PDELIMITER: The string defined as content separator / delimiter of the string
XXTMP: The array that will contains the separated strings
Returned value: Number of separated elements

Funprog F_SPLIT(PPSTR,PDELIMITER,XXTMP)
Value Char PPSTR
Value Char PDELIMITER
Variable Char XXTMP
    Local Integer XCONTA
    Local Integer XSTART
    XCONTA = 0
    XSTART = 1
    If instr(XSTART,PPSTR,PDELIMITER) > 0 Then
        Repeat
            XXTMP(XCONTA) = mid$(PPSTR,XSTART,instr(XSTART,PPSTR,PDELIMITER)-XSTART)
            XSTART = instr(XSTART,PPSTR,PDELIMITER)+1
            XCONTA += 1
        Until instr(XSTART,PPSTR,PDELIMITER) = 0
    Endif
    If XSTART <= len(PPSTR) Then
        XXTMP(XCONTA) = mid$(PPSTR,XSTART,len(PPSTR)-XSTART+1)
    Else
        XCONTA = XCONTA - 1
    Endif
End XCONTA

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *