PDA

View Full Version : [Problem resolved]Comparing chars in two strings.




alexandergre
Aug 6, 2009, 01:28 PM
my app is about learning the Swedish language.
the use taps on PLAY button. A voice will say a word. e.g: "Sweden is great".(but in swedish)
The user writes what he heard.

But when is come to comparing the users answer and the source text, Im in a big trouble.

source text= @"Sweden is great";
inputText=@"Sweden iz great";
int correctWords = 0;


how can I compare so that the user gets 1 point for each correct word?
I found some help here but I dont get a single line. search for NSString Class Reference in Xcode documentation.

Thank you very much.
Please help me! :( ;)



PhoneyDeveloper
Aug 6, 2009, 01:59 PM
You could either use NSScanner to break up the strings into words or use componentsSeparatedByString or componentsSeparatedByCharactersInSet to break up the strings into words. Compare using isEqualToString or possibly using one of the compare methods so you can have more options for the comparison. I strongly recommend that you not use characterAtIndex for comparisons between strings because of the complications of unicode.

Frankly this kind of comparison will be a little tricky. How many points does this get:

@"Sweden is not great"

alexandergre
Aug 6, 2009, 02:52 PM
Thank you very much for the reply.



Frankly this kind of comparison will be a little tricky. How many points does this get:

@"Sweden is not great"
Yes, thats a tricky one. Im thinking about that right now. :)

well if source has 3 words in it and the user types 4 words then
only the first three words are counted/go to comparison.
and he will get -2 points because of 1 extra word & 1 wrong word.

Shall I put the Source words in an array and the input words in another one?

dejo
Aug 6, 2009, 04:15 PM
and he will get -2 points because of 1 extra word & 1 wrong word.
He didn't get any points for "Sweden is"?

Also, I'm curious how you are going to handle inexact translations. For example, what if the user types "Sweden is magnificent"?

mccannmarc
Aug 6, 2009, 05:17 PM
Could you not save yourself a tonne of effort and just have a multiple choice answer list for the user to select an answer from? Heck you could even do a nice interface similar to the way you play hangman where you have the structure of the sentence displayed as blank boxes and you could drag the correct words from a list of jumbled up words to fill in the blanks.

To do this the way you want to do it, you will need some pretty advanced algorithm that is aware of differences in language structure and as dejo mentioned, multiple meanings for words + probably a lot of other things I haven't even thought of. Not doing this perfectly could and WILL result in bad reviews from frustrated customers. Learning a new language is hard enough as it is and the tool you are using to learn it with should not be a barrier in any way, shape or form.

Just my 2 cents but definitely food for thought

alexandergre
Aug 6, 2009, 09:06 PM
is there a way to shorten this code:
NSMutableArray *Words = [NSMutableArray array];
[Words addObject:@"cat"];
[Words addObject:@"dog"];
[Words addObject:@"Search"];
[Words addObject:@"computer"];
[Words addObject:@"space"];
[Words addObject:@"Dog"];

PhoneyDeveloper
Aug 6, 2009, 09:22 PM
arrayWithObjects:

alexandergre
Aug 6, 2009, 09:40 PM
arrayWithObjects:

like this:
NSMutableArray *Words = [NSMutableArray array];
Words =[NSMutableArray arrayWithObjects:@"cat",@"DOG",@"Horse",@"Hemma",@"House",@"Mouse"];

it didtn work. :(

PhoneyDeveloper
Aug 6, 2009, 10:02 PM
NSMutableArray *words = [NSMutableArray arrayWithObjects:@"cat",@"DOG",@"Horse",@"Hemma",@"House",@"Mouse", nil];

Dude, you need to get a book on Objective-C.

alexandergre
Aug 7, 2009, 09:18 AM
NSMutableArray *words = [NSMutableArray arrayWithObjects:@"cat",@"DOG",@"Horse",@"Hemma",@"House",@"Mouse", nil];

Dude, you need to get a book on Objective-C.

I know. Im a beginner. But thanx for the answer. ;)