29.07.2011, 06:53
Use: Able to select a single group of characters from a string.
Usage: Segment(string[], num)
Example:
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.
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.
Usage: Segment(string[], num)
Example:
Код:
new string[256], word[64]; format(string, sizeof(string), "This is an example string"); word = Segment(string, 4);
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]; }
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.