Page 1 of 1

ExplodeString( p_szOutput[][], p_nMax, p_nSize, p_szInput[], p_szDelimiter )

Posted: Tue Aug 18, 2026 6:09 am
by Archive-Poster

Code: Select all

stock ExplodeString( p_szOutput[][], p_nMax, p_nSize, p_szInput[], p_szDelimiter ) { // Function by xeroblood
    new nIdx = 0, l = strlen(p_szInput)
    new nLen = (1 + copyc( p_szOutput[nIdx], p_nSize, p_szInput, p_szDelimiter ))
    while( (nLen < l) && (++nIdx < p_nMax) )
        nLen += (1 + copyc( p_szOutput[nIdx], p_nSize, p_szInput[nLen], p_szDelimiter ))
    return nIdx
}

Re: ExplodeString( p_szOutput[][], p_nMax, p_nSize, p_szInput[], p_szDelimiter )

Posted: Tue Aug 18, 2026 6:09 am
by Archive-Poster
Not a bad function, if it does what it seems to from the source/name.

Not sure if I need it right atm, strtok() usually does it for me, but for de-concatenating strings for Vault / SQL storage it would be useful.

Re: ExplodeString( p_szOutput[][], p_nMax, p_nSize, p_szInput[], p_szDelimiter )

Posted: Tue Aug 18, 2026 6:11 am
by Archive-Poster
I love parsing messages with "|" for a delimiter, so this is perfect for my plugins

Re: ExplodeString( p_szOutput[][], p_nMax, p_nSize, p_szInput[], p_szDelimiter )

Posted: Tue Aug 18, 2026 6:12 am
by Archive-Poster
Well the pipe is the only real delimiter, tbh.

I just wish there were something as fast and powerful as Caché's $Piece function ... ah, well.

It's pretty handy for me too, but I decided to write my own version instead.
Though without copyc ... I just went for looping through the array comparing cells.

Re: ExplodeString( p_szOutput[][], p_nMax, p_nSize, p_szInput[], p_szDelimiter )

Posted: Tue Aug 18, 2026 6:12 am
by Archive-Poster
This can be done in a single, optimized and incomplete loop rather than in standalone and nested loops.

Re: ExplodeString( p_szOutput[][], p_nMax, p_nSize, p_szInput[], p_szDelimiter )

Posted: Tue Aug 18, 2026 6:12 am
by Archive-Poster

Code: Select all

stock ExplodeString( Output[][], Max, Size, Input[], Delimiter )
{
    new Idx, l = strlen(Input), Len;
    do Len += (1 + copyc( Output[Idx], Size, Input[Len], Delimiter ));
    while( (Len < l) && (++Idx < Max) )
    return Idx;
}