AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   RegEx Type Function? (https://forums.alliedmods.net/showthread.php?t=49269)

Minimum 12-31-2006 00:44

RegEx Type Function?
 
Do you have any idea on how I would go about making a function that would cut up a string and divide it up based on separation characters? I could take one I found out of someone's plugin but that is petty theft and completely wrong in my book.

This is a simple explanation on how it should work.

Say I send in a string with this infomation in it.
- "Steam:Blah1|Steam:Blah2|Steam:Blah3"
I would specify that the | character is the separation character.
Then it would cut the string up and return this:
Code:

sc_output[0] = "Steam:Blah1"
sc_output[1] = "Steam:Blah2"
sc_output[2] = "Steam:Blah3"

I have no idea how Regular Expressions work so I don't even know if this would be classified in the Regular Expression category. Thanks.

Edit: The person or people who help will be in the credits of the plugin I just started.

teame06 12-31-2006 01:29

Re: RegEx Type Function?
 
Quote:

Originally Posted by Minimum (Post 422126)
I could take one I found out of someone's plugin but that is petty theft and completely wrong in my book.


All plugins are under GPL. You can use any of it as long as you give them credit. It not stealing. This is a open source community.

Minimum 12-31-2006 04:48

Re: RegEx Type Function?
 
Still, I just couldn't bring myself to copy from someone. Call me whatever you want. Its just how I am. :P

spider853 12-31-2006 08:06

Re: RegEx Type Function?
 
Maybe Pawn Have Split function??

Brad 12-31-2006 09:05

Re: RegEx Type Function?
 
Either use regex (overkill) or use the parse or strbreak functions.

Minimum 12-31-2006 14:22

Re: RegEx Type Function?
 
I know how to use parse but I don't think it will let me put it into a loop and break down the string until its all broken down. I don't know how to use strbreak at all.

stupok 12-31-2006 16:15

Re: RegEx Type Function?
 
There is a function made specifically for this purpose, called strtok().

Minimum 12-31-2006 16:43

Re: RegEx Type Function?
 
Do you think this is a good way of doing it?

Code:
public string_split(output[][],size,input[],limit) {     new right[1024]     format(right,1023,"%s",input)     for(new x=0;x < limit;x++) strtok(right,output[x],size,right,1023,'|',0)     return PLUGIN_CONTINUE }

jim_yang 01-01-2007 08:05

Re: RegEx Type Function?
 
FYI, still not good enough.
Code:
#include <amxmodx> #include <amxmisc> #define PLUGIN "Test" #define VERSION "1.0" #define AUTHOR "Jim" #define MAX_STRLEN 32 #define MAX_PLAYER 32 new Player_Steam[MAX_PLAYER][MAX_STRLEN] new  const test_string[3][] = {         "steam:1234567",         "steam:7654321|",         "steam:1234567|steam:7654321|steam:8888888" } public plugin_init() {         register_plugin(PLUGIN, VERSION, AUTHOR)         register_clcmd("test", "test") } public test(id) {         static j         new num = string_split(test_string[j++ % 3])         for(new i = 0; i < num; i++)         {                 client_print(id, print_chat, Player_Steam[i])         }         return PLUGIN_HANDLED } public string_split(const source[]) {         new i, j, k, c         while((c = source[i++]))         {                 if(j == MAX_PLAYER)                         break                                 if(k < MAX_STRLEN && c != '|')                         Player_Steam[j][k++] = c                 else                 {                         Player_Steam[j][k] = 0                         k = 0                         j++                 }         }         return !i ? 0 : (!j ? 1 : (!k ? j : j + 1)) }
doesn't contain the situation of "|steam:1234567"


All times are GMT -4. The time now is 22:23.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.