Getting Length of NSRange (or finding a Substring)


I have a NSString, obtained from a URL. I perform an rangeOfString search to check if a given String is inside the NSString like this:

set we_range to we_serverOutputTest's rangeOfString_("WEBCAMOK")

The NSRange looks like this, which is correct:

I now try to find out if the length of the range is 32 (substring is found) or 0 (substring is not found).

However, when I use the endSpecifier object, it doesn’t seem to do anything, or at least not something I can work with.

set we_rangerLength to we_range's endSpecifier()

I dont know what type the return is, or rather how to handle the return type.

Or is there a better way to find out if a substring is inside another string? A bool-result is fine.

NSRanges aren’t Cocoa objects, they’re actually C structs. From AS, you can just treat them as records, so:

set we_range to we_serverOutputTest's rangeOfString_("WEBCAMOK")
log |location| of we_range
log |length| of we_range

That easy?
I feel stupid now :slight_smile: