For scripting examples for learning how to use AMXX.
Archive-Poster
Posts: 1249
Gender:
Archive-Poster
Profile
Joined: Tue Aug 04, 2026 2:18 am
Gender:
Post
by Archive-Poster » Tue Aug 18, 2026 6:09 am
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
}
Archive-Poster
Posts: 1249
Gender:
Archive-Poster
Profile
Joined: Tue Aug 04, 2026 2:18 am
Gender:
Post
by Archive-Poster » Tue Aug 18, 2026 6:09 am
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.
Archive-Poster
Posts: 1249
Gender:
Archive-Poster
Profile
Joined: Tue Aug 04, 2026 2:18 am
Gender:
Post
by Archive-Poster » Tue Aug 18, 2026 6:11 am
I love parsing messages with "|" for a delimiter, so this is perfect for my plugins
Archive-Poster
Posts: 1249
Gender:
Archive-Poster
Profile
Joined: Tue Aug 04, 2026 2:18 am
Gender:
Post
by Archive-Poster » Tue Aug 18, 2026 6:12 am
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.
Archive-Poster
Posts: 1249
Gender:
Archive-Poster
Profile
Joined: Tue Aug 04, 2026 2:18 am
Gender:
Post
by Archive-Poster » Tue Aug 18, 2026 6:12 am
This can be done in a single, optimized and incomplete loop rather than in standalone and nested loops.
Archive-Poster
Posts: 1249
Gender:
Archive-Poster
Profile
Joined: Tue Aug 04, 2026 2:18 am
Gender:
Post
by Archive-Poster » Tue Aug 18, 2026 6:12 am
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;
}
Users browsing this forum: No registered users and 1 guest