Raised This Month: $ Target: $400
 0% 

Empty string? How can I check?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
killergirl
Senior Member
Join Date: Jul 2010
Old 05-06-2011 , 17:45   Empty string? How can I check?
Reply With Quote #1

I'm building up a plugin that saves data into a file. The problem is with the number of arguments. I'm trying to save 4 values (IT WORKS) but, If I execute the command with 3 values, the data line is also created, but with 3 values I can't make anything (for different functions). Anyway... this is the code:

PHP Code:
public function(idlvlcid)
{
   if(!
cmd_access(idlvlcid4))
      return 
PLUGIN_HANDLED

   read_argv
(1argOne31)
   
read_argv(2argTwo31)
   
read_argv(3argThree31)
   
read_argv(4argFour31)

I know I can't have 4 arguments, but maybe is there a way to use 4 arguments.
killergirl is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 05-06-2011 , 18:20   Re: Empty string? How can I check?
Reply With Quote #2

Title says a different thing... but anyway: if(strlen(string) > 0) or just if(string[0]) to check an empty string.

About the arguments, you can get all arguments stacked together with read_args() if you're just going to add all of them like that anyway.

And about less than 4 arguments, you should modify cmd_access()'s 4th argument to 1, that sets the required number of arguments, that's why you can't use less.
__________________
Hunter-Digital is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-06-2011 , 21:16   Re: Empty string? How can I check?
Reply With Quote #3

I think the answer to your question lies here: When using cmd_access() the command itself is considered an argument. If you want it to require 4 arguments be provided by the user with the command then you need to change the 4 to 5.

P.S. What is up with your title? A little misleading .
__________________
fysiks is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 05-06-2011 , 21:19   Re: Empty string? How can I check?
Reply With Quote #4

read_argv() returns the number of characters in the string.

Just check if that is 0.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
killergirl
Senior Member
Join Date: Jul 2010
Old 05-07-2011 , 04:42   Re: Empty string? How can I check?
Reply With Quote #5

My bad, because I post so quickly. I wanted to check if argument 4 is empty. If is empty than the function is returned.

PHP Code:

if(!cmd_access(idlvlcid1))
      return 
PLUGIN_HANDLED

if(argFour[0])
{
   
console_print(index"please use all values !")
}

return 
That is correct?


Edit:

I found the answer !

PHP Code:
if(strlen(argFour) <= 0)
{
   
//this means is empty

Thank you for support !

Last edited by killergirl; 05-07-2011 at 05:12.
killergirl is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-07-2011 , 06:07   Re: Empty string? How can I check?
Reply With Quote #6

read_argv(4, argFour, 31) already returns the length, as xolent already told you.
Please read people answers ;)
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-07-2011 , 13:55   Re: Empty string? How can I check?
Reply With Quote #7

Why not do this:

PHP Code:
if(!cmd_access(idlvlcid5)) 
It will require the player to use 4 arguments when using the command.
__________________
fysiks is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 05-07-2011 , 14:00   Re: Empty string? How can I check?
Reply With Quote #8

I think that if you pass "" as argument, it could be counted, not sure though.
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 05-07-2011 , 14:16   Re: Empty string? How can I check?
Reply With Quote #9

Quote:
Originally Posted by ConnorMcLeod View Post
I think that if you pass "" as argument, it could be counted, not sure though.
That's true, read_argc() counts "" as argument, I just tested it.
__________________
Hunter-Digital is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 05-07-2011 , 14:28   Re: Empty string? How can I check?
Reply With Quote #10

Quote:
Originally Posted by ConnorMcLeod View Post
I think that if you pass "" as argument, it could be counted, not sure though.
Interesting. So, the questoin then becomes how likely is someone going to do that?

So, every function that uses cmd_access() without checking arg length of all arguments has a potential breaking point .
__________________
fysiks is offline
Reply


Thread Tools
Display Modes

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 04:31.


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