Raised This Month: $ Target: $400
 0% 

Replacing a part of a message


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bibu
Veteran Member
Join Date: Sep 2010
Old 12-03-2010 , 02:50   Replacing a part of a message
Reply With Quote #1

I am using this in my code:

PHP Code:
client_print(idprint_chat"bibu said %s to all"g_szWelcomeMsgs[g_RandomMsg]) 
I also use the welcome msg in a menu, so it does display like this:

bibu said \yhi

Now in the menu it looks colored, but I want that if \y or \w or \r, \d contained, removed in the client_print part.
Can someone help me with that?
bibu is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 12-03-2010 , 02:56   Re: Replacing a part of a message
Reply With Quote #2

Code:
new szMessage[ sizeof( g_szWelcomeMsgs[ ] ) ]; copy( szMessage, charsmax( szMessage ), g_szWelcomeMsgs[ g_RandomMsg ] ); new const szMenuCodes[ ][ ] = { "\r", "\y", "\w", "\d", "\R" }; for( new i = 0; i < sizeof( szMenuCodes ); i++ ) {     replace_all( szMessage, charsmax( szMessage ), szMenuCodes[ i ], "" ); } client_print( id, print_chat, "bibu said %s to all", szMessage );
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 12-03-2010 , 04:01   Re: Replacing a part of a message
Reply With Quote #3

Quote:
Originally Posted by Seta00 View Post
here'sapostwithnowhitespacetocompensatethe previouspost
Sorry.

Code:
new szMessage[sizeof(g_szWelcomeMsgs[])]; copy(szMessage,charsmax(szMessage),g_szWelcomeMsgs[g_RandomMsg]); new const szMenuCodes[][]={"\r","\y","\w","\d","\R"}; for(new i=0;i<sizeof(szMenuCodes);i++)     replace_all(szMessage,charsmax(szMessage),szMenuCodes[i],""); client_print(id,print_chat,"bibu said %s to all",szMessage);
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Seta00
The Seta00 user has crashed.
Join Date: Jan 2010
Location: Berlin
Old 12-03-2010 , 03:40   Re: Replacing a part of a message
Reply With Quote #4

here'sapostwithnowhitespacetocompensatethe previouspost
Seta00 is offline
bibu
Veteran Member
Join Date: Sep 2010
Old 12-03-2010 , 05:50   Re: Replacing a part of a message
Reply With Quote #5

Works perfectly, thanks exolent. Couldn't understand seta's message, but however.
bibu is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 12-03-2010 , 10:22   Re: Replacing a part of a message
Reply With Quote #6

Quote:
Originally Posted by bibu View Post
Couldn't understand seta's message, but however.
He meant that Exolent is using too much spacing in his code. While I also don't see how such spacing can look good or improve readability for anyone, it's a matter of one's taste.

Also it would be more efficient to not use 2D arrays for such code. Here's my way tho:
Code:
new message[sizeof(g_szWelcomeMsgs[])]; copy(message, charsmax(message), g_szWelcomeMsgs[g_RandomMsg]);   RemoveAll(message, charsmax(message), "\r"); RemoveAll(message, charsmax(message), "\y"); RemoveAll(message, charsmax(message), "\w"); RemoveAll(message, charsmax(message), "\d"); RemoveAll(message, charsmax(message), "\R");   client_print(id, print_chat, "bibu said %s to all", message);   // ...   RemoveAll(message[], length, text[])         while (replace(message, length, text, "")) {}
__________________

Last edited by hleV; 12-03-2010 at 10:33.
hleV is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-03-2010 , 13:48   Re: Replacing a part of a message
Reply With Quote #7

Quote:
Originally Posted by hleV View Post
He meant that Exolent is using too much spacing in his code. While I also don't see how such spacing can look good or improve readability for anyone, it's a matter of one's taste.

Also it would be more efficient to not use 2D arrays for such code. Here's my way tho:
Code:
new message[sizeof(g_szWelcomeMsgs[])]; copy(message, charsmax(message), g_szWelcomeMsgs[g_RandomMsg]);   RemoveAll(message, charsmax(message), "\r"); RemoveAll(message, charsmax(message), "\y"); RemoveAll(message, charsmax(message), "\w"); RemoveAll(message, charsmax(message), "\d"); RemoveAll(message, charsmax(message), "\R");   client_print(id, print_chat, "bibu said %s to all", message);   // ...   RemoveAll(message[], length, text[])         while (replace(message, length, text, "")) {}
Why don't you just use replace_all()?
__________________
fysiks is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 12-03-2010 , 13:46   Re: Replacing a part of a message
Reply With Quote #8

I think he was making it easier to review/add/remove the replace-characters if needed, not so much that a 2d array was required; this allows the user to easily add/remove items without touching any of the other code. I don't think the CPU would take a hit using either method, though. Plus IMO his looks a little cleaner, to each his own.
__________________
Bugsy is offline
hleV
Veteran Member
Join Date: Mar 2007
Location: Lithuania
Old 12-03-2010 , 17:16   Re: Replacing a part of a message
Reply With Quote #9

Why should I?
__________________
hleV is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-03-2010 , 18:23   Re: Replacing a part of a message
Reply With Quote #10

replace_all() uses more code and is supposed to be used to avoid infinite replacement, but here it won't happen, so it's fine while + replace. Btw, I agree with Bugsy.
__________________
Arkshine 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 11:19.


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