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.

inside custom component

Adobe AIR Development

Reply
Developer
Posts: 193
Registered: ‎12-29-2010
My Device: Bold 9900
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

Developer
Posts: 1,104
Registered: ‎12-29-2010
My Device: PlayBook, Z10 LE, Dev Alpha C

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.

Developer
Posts: 1,104
Registered: ‎12-29-2010
My Device: PlayBook, Z10 LE, Dev Alpha C

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.

Developer
Posts: 165
Registered: ‎10-26-2010
My Device: BlackBerry® PlayBook™
My Carrier: .

Re: compare string

 

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

 

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

 

Developer
Posts: 157
Registered: ‎12-16-2010
My Device: Torch 9800, PlayBook
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.
Developer
Posts: 409
Registered: ‎12-10-2010
My Device: PlayBook
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
Developer
Posts: 889
Registered: ‎08-31-2009
My Device: 9530, 9630, 9800, 8530, 9900, 9810, 9930, PlayBook, Dev Alpha
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