Raised This Month: $ Target: $400
 0% 

RegEx Type Function?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Minimum
Senior Member
Join Date: Jun 2006
Old 12-31-2006 , 00:44   RegEx Type Function?
Reply With Quote #1

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.

Last edited by Minimum; 12-31-2006 at 00:48.
Minimum is offline
Send a message via AIM to Minimum Send a message via MSN to Minimum
teame06
i have a hat
Join Date: Feb 2005
Location: Hat City
Old 12-31-2006 , 01:29   Re: RegEx Type Function?
Reply With Quote #2

Quote:
Originally Posted by Minimum View Post
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.
__________________
No private support via Instant Message
GunGame:SM Released
teame06 is offline
Send a message via AIM to teame06
Minimum
Senior Member
Join Date: Jun 2006
Old 12-31-2006 , 04:48   Re: RegEx Type Function?
Reply With Quote #3

Still, I just couldn't bring myself to copy from someone. Call me whatever you want. Its just how I am.
Minimum is offline
Send a message via AIM to Minimum Send a message via MSN to Minimum
spider853
Senior Member
Join Date: Jul 2006
Old 12-31-2006 , 08:06   Re: RegEx Type Function?
Reply With Quote #4

Maybe Pawn Have Split function??
spider853 is offline
Send a message via ICQ to spider853
Brad
AMX Mod X Team Member
Join Date: Jun 2004
Old 12-31-2006 , 09:05   Re: RegEx Type Function?
Reply With Quote #5

Either use regex (overkill) or use the parse or strbreak functions.
__________________
Brad is offline
Minimum
Senior Member
Join Date: Jun 2006
Old 12-31-2006 , 14:22   Re: RegEx Type Function?
Reply With Quote #6

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.
Minimum is offline
Send a message via AIM to Minimum Send a message via MSN to Minimum
stupok
Veteran Member
Join Date: Feb 2006
Old 12-31-2006 , 16:15   Re: RegEx Type Function?
Reply With Quote #7

There is a function made specifically for this purpose, called strtok().
stupok is offline
Minimum
Senior Member
Join Date: Jun 2006
Old 12-31-2006 , 16:43   Re: RegEx Type Function?
Reply With Quote #8

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 }

Last edited by Minimum; 12-31-2006 at 17:04.
Minimum is offline
Send a message via AIM to Minimum Send a message via MSN to Minimum
jim_yang
Veteran Member
Join Date: Aug 2006
Old 01-01-2007 , 08:05   Re: RegEx Type Function?
Reply With Quote #9

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"
__________________
Project : CSDM all in one - 99%
<team balancer#no round end#entity remover#quake sounds#fake full#maps management menu#players punishment menu#no team flash#colored flashbang#grenade trails#HE effect#spawn protection#weapon arena#weapon upgrade#auto join#no weapon drop#one name>

Last edited by jim_yang; 01-01-2007 at 19:46.
jim_yang is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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