Upvote:1

Aprove answer
NSUInteger characterCount = [subString length];

Upvote:2

NSString *myString = [NSString stringWithFormat:@"This is a test string."];

NSInteger charCountBetween = -1;
NSRange thisRange = [myString rangeOfString:@"This"];
NSRange stringRange = [myString rangeOfString:@"string"];
if( thisRange.location != NSNotFound && stringRange.location != NSNotFound )
{
    charCountBetween = fabs(thisRange.location - stringRange.location);
    if( thisRange.location > stringRange.location )
    {
        charCountBetween -= stringRange.length;
    }
    else
    {
        charCountBetween -= thisRange.length;
    }
}

More Answer related to the Same Query

Upvote:0

NSString *myString = @"This is a test !";
NSRange match = [myString rangeOfString: @"This"];
NSRange match1 = [myString rangeOfString: @"test"];

int nbChar = match1.location - match.location;

Upvote:0

NSString *string = @"This is a test string";
NSRange firstRange = [string rangeOfString:@"This"];
NSRange secondRange = [string rangeOfString:@"string"];
if (firstRange.location != NSNotFound &&
    secondRange.location != NSNotFound &&
    secondRange.location > firstRange.location) {
    NSLog(@"Characters between: %d", secondRange.location - (firstRange.location + firstRange.length));
}

More Answer related to the Same Query

Upvote:0

NSRange range1 = [myString rangeOfString:@"This"];
NSRange range2 = [myString rangeOfString:@"string"];
NSUInteger numberOfChars = range2.location - range1.location; 

Credit Goes to: stackoverflow.com

Related question with same questions but different answers