[Include] Segment 1.0
#1

Use: Able to select a single group of characters from a string.


Usage: Segment(string[], num)


Example:
Код:
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".
The variable "word" would store this variable then.


Code: Just paste it into your script. It isn't a very big include, but it is useful.
Код:
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];
}
Limitations: This include is only able to pickup 32 segments in a string. Each string can be up to 64 characters.
These limitations could be changed but if numbers are set up to high this will not work.


Further Info: This could be useful in making commands. Please give me credit for making this.
Reply


Messages In This Thread
Segment 1.0 - by AustinJ - 29.07.2011, 06:53
Re: Segment 1.0 - by DartakousLien - 29.07.2011, 10:00
Re: Segment 1.0 - by CaHbKo - 29.07.2011, 10:21
AW: Segment 1.0 - by Pablo Borsellino - 29.07.2011, 11:32

Forum Jump:


Users browsing this thread: 1 Guest(s)