Either of these would do...

public static boolean arrayContainsSubstring( NSArray< String > array, String substring )
{
        if ( array == null || substring == null || array.count() == 0 )
                return false;
return array .componentsJoinedByString ( "|" ).toLowerCase().indexOf( substring.toLowerCase() ) >= 0;
}

// or (perhaps more efficient)

public static boolean arrayContainsSubstring( NSArray< String > array, String substring )
{
        if ( array != null && array.count() > 0 && substring != null )
        {
                String lowerSub = substring.toLowerCase();
                for ( String item : array )
                        if ( item.toLowerCase().indexOf( lowerSub ) >= 0 )
                                return true;
        }
        return false;
}

with regards,
--

Lachlan Deck


On 10/05/2008, at 12:11 AM, Joshua Paul wrote:

Oh, I was referring to your substring routine...

On May 9, 2008, at 1:05 AM, Daniele Corti wrote:

2008/5/9 Joshua Paul <[EMAIL PROTECTED]>:
In this specific instance i was looking for intersecting strings from two arrays.

Nevertheless, I'm always curious to see how people solve various problems, so if you're willing to share, please pass along a code snippet.

NSArray first, second; //assume they exist and contian your strings

NSSet firstSet = new NSSet(first);
NSSet secondSet = new NSSet(second);
NSSet intersectingsSet = firstSet.setByIntersettingSet(secondSet);

NSArray myIntersectedArray = intersectingsSet.allObjects();


TIA.

On May 8, 2008, at 5:26 PM, Don Lindsay wrote:

Are you looking for a substring of a string in an array? Or are you looking for the whole string? I have written a routine to find the substring of a string in an array, if that would help.


_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to