 |
 |
nsscanner
|
 |
|
 |
|
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status:
Offline
|
|
anybody ever worked with nsscanner and strings? i made it to scan for ints, but with strings, i'm lost.
basically, what i want to know is whether a string contains another string, like "if (stringA.indexOf(stringB) != -1)" in java.
anybody?
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status:
Offline
|
|
ok... found a way. not very elegant, but it works.
now: anybody have an idea how authentication works? (the small lock you click in the installer and it prompts for your password)
|
|
|
| |
|
|
|
 |
|
 |
|
Addicted to MacNN
Join Date: Mar 2000
Location: London, UK
Status:
Offline
|
|
Originally posted by seb2:
<STRONG>ok... found a way. not very elegant, but it works.
now: anybody have an idea how authentication works? (the small lock you click in the installer and it prompts for your password)</STRONG>
Straight C API with setuid root executables. You will have trouble from Java.
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Sep 2001
Location: McKinney, TX
Status:
Offline
|
|
Originally posted by seb2:
<STRONG>ok... found a way. not very elegant, but it works.</STRONG>
I hope your way didn't include the use of NSScanner if all you're doing is looking for a substring because that'd be serious overkill. The NSString class has everything you need to do that. The equivalent statement to your Java example would be:
if ([stringA rangeOfString:stringB].location != NSNotFound)
Of course, both stringA and stringB have to be NSStrings or else the statement get a little more complicated.
|
|
|
| |
|
|
|
 |
|
 |
|
Dedicated MacNNer
Join Date: Jan 2001
Location: Virginia, US
Status:
Offline
|
|
Actually you want to check if range.length != 0, not the location member. The docs define that as the indication of the string not being found (though most methods will also put NSNotFound in the location member).
But yes, NSScanner is overkill for finding substrings.
|
|
|
| |
|
|
|
 |
|
 |
|
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status:
Offline
|
|
Originally posted by TheBum:
<STRONG>if ([stringA rangeOfString:stringB].location != NSNotFound)
</STRONG>
that's exactly what i did. as i mentioned before, i come from java and was only looking for methods beginning with "index".
ignorant me. 
|
|
|
| |
|
|
|
 |
|
 |
|
Mac Enthusiast
Join Date: Sep 2001
Location: McKinney, TX
Status:
Offline
|
|
Originally posted by lindberg:
<STRONG>Actually you want to check if range.length != 0, not the location member. The docs define that as the indication of the string not being found (though most methods will also put NSNotFound in the location member).</STRONG>
Apple's NSString docs state that the "not found" NSRange is returned as { NSNotFound, 0 }, so I suppose either check is valid. I chose the NSNotFound check because it provides better self-documentation as to the intent of the statement.
[ 11-02-2001: Message edited by: TheBum ]
|
|
|
| |
|
|
|
 |
 |
|
 |
|
|
|
|
|

|
|
 |
Forum Rules
|
 |
 |
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
|
HTML code is Off
|
|
|
|
|
|
 |
 |
 |
 |
|
 |
|