Wednesday, 22 January 2014

Counting the particular words

str = @"Cricket is a bat-and-ball game played between two teams of 11 players on a field,at the center of which is a rectangular 22-yard long pitch.one team bats,trying to score as many run as possible while the other team bowels and fields,trying to dissmiss the batsmen and thus limit the runs scored by the batting team.A run is scored by the striking batsman hitting the ball with his bat,running to the opposite end of the pith and touching the crease there without being dismissed.The teams switch between batting and fielding at the end of an innings. ";

    NSString *s=textbox.text;  //Type the word here
    NSRange r = NSMakeRange(0, str.length);
    int count = 0;
    for (;;) {
        r = [str rangeOfString:s options:NSCaseInsensitiveSearch range:r];
        if (r.location == NSNotFound) {
            break;
        }
        count++;
        r.location++;
        r.length = str.length - r.location;
    }

label.text=[NSString stringWithFormat:@"%d",count];

1 comment:

  1. A run is scored by the striking batsman hitting the ball with his bat,running to the opposite end of the pith and touching the crease there without being dismissed. Unites States city distances

    ReplyDelete