Welcome!

Welcome to the Official BlackBerry Support Community Forums. This is your resource to discuss support topics with your peers, and learn from each other. New to the forum? Please visit the ‘Getting Started’ link below.
inside custom component

Adobe AIR Development

Reply
Developer
gpatton
Posts: 172
Registered: ‎12-29-2010
My Carrier: Rogers

compare string

Hi,

 

Is there any way in ActionScript to compare strings?

Normally in Java there is a .equals() method.

 

What about in AS?

 

i want to check if let's say, if x is equal to "PlayBook".

 

 

G

Please use plain text.
Developer
UberschallSamsara
Posts: 685
Registered: ‎12-29-2010

Re: compare string

You could compare string lengths and then check that  the index of the first string in the second one is zero, using the indexOf() String method.  Also, you can pre-trim the strings with the mx.utils.StringUtil.trim() static class method.

Please use plain text.
Developer
UberschallSamsara
Posts: 685
Registered: ‎12-29-2010

Re: compare string

BTW, I'm also new to AS3 and from your question I assumed you'd looked for an "==" operator & not found one.  However now that I look closer, since I'll need to do string comparisons as well, according to p. 133 of this:

 

http://livedocs.adobe.com/flex/3/progAS_flex3.pdf

 

 

"You can use the following operators to compare strings: <, <=, !=, ==, =>, and >."

 

PDF is 500+ pages of AS3 documentation straight from the horse's mouth.

Please use plain text.
Developer
studiochris
Posts: 165
Registered: ‎10-26-2010
My Carrier: .

Re: compare string

 

String.search();
String.match();
String.indexOf();
String.lastIndexOf();

 

Any of the above could work, depending on your use case.

 

Please use plain text.
Developer
p3pp3r
Posts: 157
Registered: ‎12-16-2010
My Carrier: I carry it myself

Re: compare string

 


UberschallSamsara wrote:

 

PDF is 500+ pages of AS3 documentation straight from the horse's mouth.


Thanks for the link - never seen it before - really useful reference!!!!

 

----------
If you find this post helpful please "like" it and accept as a solution.
Please use plain text.
Developer
TheDarkIn1978
Posts: 409
Registered: ‎12-10-2010
My Carrier: N/A

Re: compare string

[ Edited ]

 

trace("Playbook" == "playbook");  //false
trace("Playbook" != "playbook");  //true
trace("This is stupid easy" != "This is stupid easy"); //false
trace("This is stupid easy" == "This is stupid easy"); //true

 

if you're trying to determine the OS at runtime, something like the following should work for you:

 

 

//Resoslve Operating System

private function resolveOperatingSystem():String
     {
     if         (Capabilities.os.toLowerCase().indexOf("win") > -1) return "Windows";	
     else if	(Capabilities.os.toLowerCase().indexOf("mac") > -1) return "Mac";
     else if	(Capabilities.os.toLowerCase().indexOf("qnx") > -1) return "PlayBook";
     else if	(Capabilities.manufacturer.toLowerCase().indexOf("and") > -1) return "Android";
     else if	(Capabilities.os.toLowerCase().indexOf("iph") > -1) return "iPhone";
     }

 

 


PlayBook Applications:
Drop Swatch
Please use plain text.
Developer
Ebscer
Posts: 729
Registered: ‎08-31-2009
My Carrier: Verizon

Re: compare string

Unlike Java ActionScript actually lets you compare strings the exact same way you compare everything else. I for one, do not miss the clunky .equals() method one bit...


Read my thoughts on BlackBerry Development at news.ebscer.com
Please use plain text.