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

For scripting examples for learning how to use AMXX.
User avatar
Archive-Poster
Posts: 1249
Gender:
United States of America

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

Post 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
}
User avatar
Archive-Poster
Posts: 1249
Gender:
United States of America

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

Post 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.
User avatar
Archive-Poster
Posts: 1249
Gender:
United States of America

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

Post by Archive-Poster »

I love parsing messages with "|" for a delimiter, so this is perfect for my plugins
User avatar
Archive-Poster
Posts: 1249
Gender:
United States of America

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

Post 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.
User avatar
Archive-Poster
Posts: 1249
Gender:
United States of America

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

Post by Archive-Poster »

This can be done in a single, optimized and incomplete loop rather than in standalone and nested loops.
User avatar
Archive-Poster
Posts: 1249
Gender:
United States of America

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

Post 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;
}
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest