Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > nsscanner

nsscanner
Thread Tools
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status: Offline
Reply With Quote
Oct 31, 2001, 12:16 AM
 
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?
     
seb2  (op)
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status: Offline
Reply With Quote
Oct 31, 2001, 02:11 AM
 
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
Reply With Quote
Oct 31, 2001, 01:52 PM
 
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
Reply With Quote
Nov 1, 2001, 10:21 PM
 
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
Reply With Quote
Nov 2, 2001, 01:55 AM
 
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.
     
seb2  (op)
Grizzled Veteran
Join Date: Feb 2001
Location: Germany
Status: Offline
Reply With Quote
Nov 2, 2001, 03:43 AM
 
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
Reply With Quote
Nov 2, 2001, 10:18 AM
 
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 ]
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:55 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2