=== I believe it doesn't affect strings. if name == null and category = new String() then they are not == or ===, but their valueOf may be ""
________________________________ From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf Of simonjpalmer Sent: Wednesday, April 04, 2007 9:42 AM To: flexcoders@yahoogroups.com Subject: [flexcoders] Re: question about string equality Good point, I didn't include the declarations. They are both strongly typed Strings, I don't use objects anywhere in my code. co is a custom AS object of type "Competitor", here's the declaration of the name member: public var name:String; oc is a custom AS object of type "ObjectCategory" and here is the declaration of the category member: public var category:String = new String(); The strong typing answers the question about whether they just happen to contain strings. Other than the fact that they belong to custom objects I have written, there is nothing peculiar about either the string variables or their contents. I don't think they are in a custom namespace, but to be honest I'm not exactly sure what that means, so I can't say with certainty that they aren't. I think the answer is no. co.name gets populated by various means, either though a user gesture in a custom page or by retrieval from a java data adaptor to my server. oc.category is populated programmatically during execution of the code in question. I appreciate you guys looking at this. Right now I have it working as I expect but it is a bit worrying that I need to do the comparison in this way only in this instance. That says to me that I don't properly understand something. If I want to check equality of the content of two strings should I always be testing valueOf()? What is the overhead of using ===? --- In flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> , "Peter Farland" <[EMAIL PROTECTED]> wrote: > > What are the type declarations of the properties sc.name and > sc.category? Do they just happen to hold String values or are they typed > to enforce that they hold String values? Is there anything else unique > about these properties? Are they in a custom namespace? Are they > read-only? How were they populated in the first place? > > ________________________________ > > From: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> [mailto:flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> ] On > Behalf Of simonjpalmer > Sent: Monday, April 02, 2007 6:14 PM > To: flexcoders@yahoogroups.com <mailto:flexcoders%40yahoogroups.com> > Subject: [flexcoders] question about string equality > > > > take a look at this code snippet... > > 01 // check one doesn't already exist with this name > 02 bFound = false; > 03 for (isc = 0; isc < ss.scenarios.length && !bFound; isc++) > 04 { > 05 sc = Scenario(ss.scenarios.getItemAt(isc)); > 06 if (sc.name.valueOf() == oc.category.valueOf()) bFound = true; > 07 } > 08 if (!bFound) > 09 { > 10 // Make a new scenario > 11 sc = PlanPointFactory.makeScenario(uli, null, true, false); > 12 > 13 // add it to the snapshot > 14 ss.addScenario(sc); > 15 > 16 // add it to the local array of categories > 17 oc.objects.push(sc); > 18 } > > line 06 is the offending line. > > if I have: > > 06 if (sc.name == oc.category) bFound = true; > > the bFound flag never gets set true. I have to have the valueOf() > function in order for the equality to fire correctly. > > This is not what I expected. I thought that regular equality would > have sufficed here since sc.name and oc.category are both Strings. > > Why am I wrong and why do I need valueOf()? >