[Problem resolved]Comparing chars in two strings.

Discussion in 'iOS Programming' started by alexandergre, Aug 6, 2009.

  1. alexandergre macrumors member

    alexandergre

    Joined:
    Jul 28, 2009
    #1
    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.

    Code:
    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! :( ;)
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    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"
     
  3. alexandergre thread starter macrumors member

    alexandergre

    Joined:
    Jul 28, 2009
    #3
    Thank you very much for the reply.

    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?
     
  4. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #4
    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"?
     
  5. mccannmarc macrumors 6502

    mccannmarc

    Joined:
    Aug 15, 2008
    Location:
    Manchester, UK
    #5
    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
     
  6. alexandergre thread starter macrumors member

    alexandergre

    Joined:
    Jul 28, 2009
    #6
    is there a way to shorten this code:
    Code:
    	NSMutableArray *Words = [NSMutableArray array];
    	[Words addObject:@"cat"];
    	[Words addObject:@"dog"];
    	[Words addObject:@"Search"];
    	[Words addObject:@"computer"];
    	[Words addObject:@"space"];
    	[Words addObject:@"Dog"];
     
  7. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
  8. alexandergre thread starter macrumors member

    alexandergre

    Joined:
    Jul 28, 2009
    #8
    like this:
    Code:
    	NSMutableArray *Words = [NSMutableArray array];
    	Words =[NSMutableArray arrayWithObjects:@"cat",@"DOG",@"Horse",@"Hemma",@"House",@"Mouse"];
    it didtn work. :(
     
  9. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #9
    Code:
    NSMutableArray *words = [NSMutableArray arrayWithObjects:@"cat",@"DOG",@"Horse",@"Hemma",@"House",@"Mouse", nil];
    
    Dude, you need to get a book on Objective-C.
     
  10. alexandergre thread starter macrumors member

    alexandergre

    Joined:
    Jul 28, 2009
    #10
    I know. Im a beginner. But thanx for the answer. ;)
     

Share This Page