Raised This Month: $ Target: $400
 0% 

Decision statements with strings?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
NewBKaeK
New Member
Join Date: Aug 2008
Old 08-10-2008 , 16:34   Decision statements with strings?
Reply With Quote #1

I was wondering if this is possible, because for some reason I can't get it to work.

new Arg[32]
read_argv(1, Arg, 31)

if(Arg == 'string') { Do this }
else { Do this }

Am I doing something wrong in my code?
The error it gives me is: Array must be indexed (variable "Arg")

Thanks =]
NewBKaeK is offline
atomen
Veteran Member
Join Date: Oct 2006
Location: Stockholm, Sweden
Old 08-10-2008 , 16:38   Re: Decision statements with strings?
Reply With Quote #2

PHP Code:
static string[] = "hello";

if(
equal(string"hello"))
{
 
// String was Hello
}

else if(
contain(string"he") != -1)
{
 
// The string contained "he"

__________________
atomen is offline
Send a message via MSN to atomen
Vet
Veteran Member
Join Date: Jul 2006
Location: I|O wa
Old 08-10-2008 , 22:51   Re: Decision statements with strings?
Reply With Quote #3

What atomen is showing you is that you cannot compare strings with the == operator. You use the equal(), equali() or strcmp() functions.

For your example is would be:
new Arg[32]
read_argv(1, Arg, 31)

if(equali(Arg, "string")) { Do this }
else { Do this }
__________________
=====================================
- My Plugins -
=====================================
Vet is offline
Send a message via MSN to Vet
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 03:07.


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