Removing...
#1

I have some strings which are being sent to a stock function (for ease of use). Inside that stock function, are a few more functions which log the strings. In some of the strings are color codes (i.e. {FFFFFF}), is there a way to "weed-out" those codes?
Reply
#2

Tried Strfind and Strdel? probably very inefficient but that is the only method I can think of, Your a very capable person from what I have seen around the forums so I won't waste time writing an example, if you want me to though just say so, I have nothing better to do.


EDIT: Actually I have had some users using a method to embedd hex into OnPlayerText, and the only way I can remove it is if I return 0; and fuck off their whole message with a string find for {, I might look into this too, seems the functions I mentioned don't do what I had thought they should do.
Reply
#3

I haven't tried those because wouldn't it just search for the bracket, instead of the bracket and all the text between the first and last bracket (using the word bracket here too much)...? It would be much easier if I knew what color codes were going to be used in the string, but I don't!
Reply
#4

Regular expressions are commonly used to combat these sorts of problems.

pawn Код:
regex_replace(szMessage, "s/{[a-zA-Z\/][^>]*}//g", "", szMessage, sizeof(szMessage));
I imagine the code above should work, I ******d an example for removing HTML tags, as I couldn't remember the wildcard syntax.
Reply
#5

^

Nevermind.
Reply
#6

Quote:
Originally Posted by Calgon
Посмотреть сообщение
Regular expressions are commonly used to combat these sorts of problems.

pawn Код:
regex_replace(szMessage, "s/{[a-zA-Z\/][^>]*}//g", "", szMessage, sizeof(szMessage));
I imagine the code above should work, I ******d an example for removing HTML tags, as I couldn't remember the wildcard syntax.
OH MY GOD! Thank you for linking me to that thread! I never knew it existed. Thanks Calgon!

EDIT: Okay, slight problem! This is my code:

pawn Код:
stock SendAdminMessage(color, string[], administrator[], level = 1)
{
    foreach(Player, i)
    {
        if(pStats[i][EP_ADMINLVL] >= level)
        {
            SendClientMessage(i, color, string);
        }
    }

    regex_replace(string, "s/{[a-zA-Z\/][^>]*}//g", "", string, sizeof(string)); // line 468

    new szQuery[500];
    format(szQuery, sizeof(szQuery), "INSERT INTO `adminMessages` (`String`, `Administrator`) VALUES('%s', '%s')", string, administrator);
    mysql_query(szQuery, qDefault);
}
... and these are the errors:

Код:
C:\Users\Piccoli\Desktop\SA-MP 0.3d\gamemodes\IGRP.pwn(468) : error 027: invalid character constant
C:\Users\Piccoli\Desktop\SA-MP 0.3d\gamemodes\IGRP.pwn(468) : error 027: invalid character constant
C:\Users\Piccoli\Desktop\SA-MP 0.3d\gamemodes\IGRP.pwn(468) : warning 224: indeterminate array size in "sizeof" expression (symbol "")
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


2 Errors.
EDIT 2: Okay, it's compiling now with this code, but I don't know about using "strlen" compared to "sizeof"...

pawn Код:
regex_replace(string, \"s/{[a-zA-Z\/][^>]*}//g", "", string, strlen(string));
Reply
#7

I think those functions just screw with my GM. It's not a big deal, I've decided not to log what I originally wanted to anyways...
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)