How to search for a string including spaces in Objective C?

Posted by AlexCu on Stack Overflow See other posts from Stack Overflow or by AlexCu
Published on 2011-01-13T08:40:29Z Indexed on 2011/01/13 8:53 UTC
Read the original article Hit count: 212

I have a real basic command-line program, in Objective-C, that searches for user inputed information. Unfourtunately, the code will only read the first word in series of words that the user enters. For example, if the user enters in "Apples are great", only "Apples" is kept (and hence searched later on), excluding the "are great" part of the sentence.

Here's what I have so far:

char enteredQuery [128]; // array 'name' to hold the scanf string
NSString *searchQuery; // ending NSString to hold and compare the user inputed data

NSLog(@"Enter search query:");
scanf("%s", enteredQuery); //will read the next line

searchQuery = [NSString stringWithCString: enteredQuery encoding: NSASCIIStringEncoding]; //converts scanf data into a NSString type

I know it's got to do with me using scanf or the character-encoder conversion, but I can't seem to figure it out. Any help in solving the problem is very appreciated! Thanks.

© Stack Overflow or respective owner

Related posts about objective-c

Related posts about string