Код:
new string[256], word[64];
format(string, sizeof(string), "This is an example string");
word = Segment(string, 4);
In this example "Segment" would return the word "example" from the string "This is an example string".
Код:
stock Segment(string[], num)
{
new SegBeg[256], SegEnd[256], ComSeg, SegUsed[256], output[32][64];
SegBeg[0] = 0; SegUsed[0] = 1;
for(new i = 0; i < strlen(string); i++)
{
if(string[i] == 32)
{
SegEnd[ComSeg] = i;
ComSeg++;
SegUsed[ComSeg] = 1;
SegBeg[ComSeg] = i + 1;
}
}
SegEnd[ComSeg] = strlen(string) - 1;
for(new i = 0; i <= ComSeg; i++) if(SegUsed[i] == 1) strmid(output[i], string, SegBeg[i], SegEnd[i], 64);
return output[num];
}