1

My Cocoa app needs to parse free format text entered via NSTextView. The result of the process should be a collection of keyword strings which can then be displayed for review to the user and optionally persisted using Core Data.

I looked at NSScanner but from the samples in Apple's documentation it looks like it's not capable of presenting a list of keyword strings from a given string. Its focus seems to be more on finding a particular occurrence of a given string within another string.

Are there alternatives?

EDIT: To make this clearer: all words in the entered text are potential keywords, so basically all words delimited by spaces should be considered. Lets assume that the user can specify a minimum required length for a string to be considered a keyword to eliminate irrelevant words like "to", "of", "in" etc. Once the parsing is done, a list of parsed keywords should be presented (possibly using a table view). The user can then select or reject each keyword. Rejected keywords will be stored so the parsing can be made smarter as more texts are scanned.

Roger
  • 4,737
  • 4
  • 43
  • 68
  • This seems a bit underspecified. I'm sure NSScanner is up to the job, but without knowing, for example, how keyword string boundaries are indicated or how you know whether something is or isn't a keyword string, it's hard to tell you specifically how you'd go about it. – Chuck Dec 20 '11 at 22:41
  • I elaborated on the problem. Hopefully more clear now. – Roger Dec 20 '11 at 23:15

1 Answers1

1

You can absolutely use NSScanner to do this. All NSScanner does is go through a string character by character. It is up to you to decide what the keyword boundaries are and to interpret them using the scanner.

I suggest reading more about NSScanner in Apple's String Programming Guide.

sosborn
  • 14,676
  • 2
  • 42
  • 46