Also, any idea why these lines would give different results in different projects?
NSString *searchStr = @"\njoy\n"; NSData *strData = [searchStr dataUsingEncoding:NSUTF8StringEncoding]; const char *strBytes = [strData bytes]; When this code is in the project you sent, strBytes shows '\njoy\n' in the debugger (which is what I'd expect), but when i copy the exact code to a different project strBytes shows extra memory stuff after it, like '\njoy\n\x1b\x14\xc0' Seems very odd. On Thu, Apr 16, 2009 at 12:01 PM, Miles <vardpeng...@gmail.com> wrote: > > It looks like I have the search working like this, but I have to > double-space the dictionary file to have a leading \n. > > NSString *searchStr = @"\njoy\n"; > NSData *strData = [searchStr > dataUsingEncoding:NSUTF8StringEncoding]; > const char *strBytes = [strData bytes]; > const char *fileBytes = [stringFileContents bytes]; > char *ptr = strstr(fileBytes, strBytes); > > Is that what you were thinking? > Thanks! > > > > > > On Thu, Apr 16, 2009 at 11:47 AM, WT <jrca...@gmail.com> wrote: > >> Marcel, >> >> since he'll be dealing with the string's raw bytes, won't Miles have to >> manually add a null byte to terminate the search string? >> >> Wagner >> >> >> On Apr 16, 2009, at 7:57 PM, Marcel Weiher wrote: >> >> >>> On Apr 16, 2009, at 10:10 , Miles wrote: >>> >>> Marcel, NOW we're talking. This has really been such an eye-opening >>>> thread. >>>> >>>> Now it's googling time to try to figure out how to search for a string >>>> in there. >>>> >>> >>> 1. Get the bytes out of your search string in the encoding that your >>> dictionary is in >>> 2. surround with '\n' characters to make sure you find whole words, >>> not substrings >>> (you will need to add a leading '\n' to your strings file >>> 3. Use strnstr() -- man strnstr() >>> >>> Cheers, >>> >>> Marcel >>> >>> >> > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com