Raised This Month: $ Target: $400
 0% 

How to check for multiple spaces in chat and remove it


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
xakintosh
I run no-steam servers!
Join Date: Feb 2010
Location: Edge of nowhere
Old 01-01-2011 , 08:17   How to check for multiple spaces in chat and remove it
Reply With Quote #1

I have this deffence but it's effective for only one " " when you type multiple " " the defence not working please help me.
Code:
if(equal(szText[10]," ")) {             ColorChat(0,RED,"[%s] ^1You cannot call an admin without a reason for it!",cvarstring)             return PLUGIN_HANDLED;         }

This way is sad
Code:
if(equal(szText," ") || equal(szText,"  ") || equal(szText,"   ") || || equal(szText,"    ") || || equal(szText,"     ")) {
__________________
As soon as possible.

Last edited by xakintosh; 01-01-2011 at 15:25.
xakintosh is offline
Send a message via Yahoo to xakintosh Send a message via Skype™ to xakintosh
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 01-01-2011 , 14:45   Re: How to check for multiple spaces in chat and remove it
Reply With Quote #2

trim() removes all spaces at the beginning and end of a string.
It should do the job here by trimming the string, then check if the string is empty.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
GXLZPGX
Veteran Member
Join Date: Sep 2009
Old 01-01-2011 , 14:56   Re: How to check for multiple spaces in chat and remove it
Reply With Quote #3

Quote:
Originally Posted by xakintosh View Post
I have this deffence but it's effective for only one " " when you type " " the defence not working please help me.
Code:
if(equal(szText[10]," ")) {             ColorChat(0,RED,"[%s] ^1You cannot call an admin without a reason for it!",cvarstring)             return PLUGIN_HANDLED;         }

This way is sad
Code:
if(equal(szText," ") || equal(szText,"  ") || equal(szText,"   ") || || equal(szText,"    ") || || equal(szText,"     ")) {
also, you don't have to check for multiple spaces. You can just check if it has 2 spaces next to eachother, since equal(szText," ") has 2 spaces in it already. Not sure if I explained it correctly.
__________________
Currently accepting payment US DOLLARS ONLY for custom plugins, contact me through PM.
GXLZPGX is offline
xakintosh
I run no-steam servers!
Join Date: Feb 2010
Location: Edge of nowhere
Old 01-23-2011 , 07:18   Re: How to check for multiple spaces in chat and remove it
Reply With Quote #4

Can you show me some example to catch it please.
__________________
As soon as possible.
xakintosh is offline
Send a message via Yahoo to xakintosh Send a message via Skype™ to xakintosh
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 01-23-2011 , 07:36   Re: How to check for multiple spaces in chat and remove it
Reply With Quote #5

Code:
while( replace(string, charsmax(string), "  ", " ") ) {}
__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 01-23-2011 at 15:11.
ConnorMcLeod is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 01-23-2011 , 13:58   Re: How to check for multiple spaces in chat and remove it
Reply With Quote #6

@xakintosh
I already said to use trim() to remove spaces before and after strings.
If you wanted to remove all multi-spaces in chat (not just before and after) then continue reading my post.

@Connor
That wouldn't work in all situations.
It would only work for clearing all double-spaces that don't touch other double-spaces.

Example:

Code:
new string[11] = "    lol   " //(4 - lol - 3)

replace_all(string, charsmax(string), "  ", " ")

/*
1st iteration:
"    lol   "
 ^^ are found and replaced with " "
"   lol   "
 ^ is no longer touched

2nd iteration:
"   lol   "
 #^^ are found and replaced with " "
"  lol   "
 #^ is no longer touched

3rd iteration:
"  lol   "
 #####^^ are found and replaced with " "
"  lol   "
 #####^ is no longer touched

4th iteration:
"  lol  "
 ######

replace_all() does not check after it replaces.
Therefore it's replacement is not checked with what is after it so those remaining multi-spaces are unchecked.
*/
Code:
// better method for this situation:
while(replace(string, charsmax(string), "  ", " ")) { }
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 01-23-2011 , 15:11   Re: How to check for multiple spaces in chat and remove it
Reply With Quote #7

Edited, but you did the same, didn't thought about it ;)
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
xakintosh
I run no-steam servers!
Join Date: Feb 2010
Location: Edge of nowhere
Old 01-24-2011 , 09:03   Re: How to check for multiple spaces in chat and remove it
Reply With Quote #8

I Try some times but it's messy can you help me to improve the system ?
Code:
if(equali(szText,"/calladmin ",10) && szText[10]) { // Here i hook the command from chat         // ==========================================         while(replace(szText[10], charsmax(szText), "  ", " ")) {             if(equal(szText[10]," ") || equal(szText[10],"  ")) {                   ColorChat(0,RED,"[%s] ^1You cannot call an admin without a reason for it!",cvarstring)                 return PLUGIN_HANDLED             }             ColorChat(0,RED,"[%s] ^1fuck off",cvarstring)             return PLUGIN_HANDLED         }

*FIXED
Code:
while(replace(szText[10], charsmax(szText), "  ", " ") || equal(szText[10]," ")) {             ColorChat(0,RED,"[%s] ^1You cannot call an admin without a reason for it!",cvarstring)             return PLUGIN_HANDLED         }
__________________
As soon as possible.

Last edited by xakintosh; 01-24-2011 at 09:26.
xakintosh is offline
Send a message via Yahoo to xakintosh Send a message via Skype™ to xakintosh
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 01-24-2011 , 11:11   Re: How to check for multiple spaces in chat and remove it
Reply With Quote #9

Why did you put your code inside the replace loop?
The brackets were there because no code was supposed to go inside of it.
Code:
        while(replace(szText[10], charsmax(szText) - 10, "  ", " ")) { }         if(equal(szText[10]," ")) {               ColorChat(0,RED,"[%s] ^1You cannot call an admin without a reason for it!",cvarstring)             return PLUGIN_HANDLED         }         ColorChat(0,RED,"[%s] ^1fuck off",cvarstring)         return PLUGIN_HANDLED
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] 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 14:19.


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