Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7835967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:53:58+00:00 2026-06-02T13:53:58+00:00

I have NSString *string = @Helo; and NSString *editedString = @Hello; . How find

  • 0

I have NSString *string = @"Helo"; and NSString *editedString = @"Hello";. How find index for changed character or characters (for example here is @"l").

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T13:54:08+00:00Added an answer on June 2, 2026 at 1:54 pm

    I’ve written a category on NSString that will do what you want. I’ve used my StackOverflow username as a postfix on the category method. This is to stop an unlikely potential future collision with a method of the same name. Feel free to change it.

    First the interface definition NSString+Difference.h:

    #import <Foundation/Foundation.h>
    
    @interface NSString (Difference)
    
    - (NSInteger)indexOfFirstDifferenceWithString_mttrb:(NSString *)string;
    
    @end
    

    and the implementation ‘NSString+Difference.m`:

    #import "NSString+Difference.h"
    
    @implementation NSString (Difference)
    
    - (NSInteger)indexOfFirstDifferenceWithString_mttrb:(NSString *)string; {
    
        // Quickly check the strings aren't identical
        if ([self isEqualToString:string]) 
            return -1;
    
        // If we access the characterAtIndex off the end of a string
        // we'll generate an NSRangeException so we only want to iterate
        // over the length of the shortest string
        NSUInteger length = MIN([self length], [string length]);
    
        // Iterate over the characters, starting with the first
        // and return the index of the first occurence that is 
        // different
        for(NSUInteger idx = 0; idx < length; idx++) {
            if ([self characterAtIndex:idx] != [string characterAtIndex:idx]) {
                return idx;
            }
        }
    
        // We've got here so the beginning of the longer string matches
        // the short string but the longer string will differ at the next
        // character.  We already know the strings aren't identical as we
        // tested for equality above.  Therefore, the difference is at the
        // length of the shorter string.
    
        return length;        
    }
    
    @end
    

    You would use the above as follows:

    NSString *stringOne = @"Helo";
    NSString *stringTwo = @"Hello";
    
    NSLog(@"%ld", [stringOne indexOfFirstDifferenceWithString_mttrb:stringTwo]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's assume I have the string NSString* myString = @Hello,; How can I remove
I have a NSString with string like hello. Now I want to convert the
i have a String NSString *const kAUrl = @ http://www.google/start.php?show=best&usr=(here)&pwd=x ; and i want
Example: I have this Objective-C code: +(NSString*)stringWithString:(NSString*)string; String: is the name of the argument
I have a string : NSString *s = @a+v+c+d; Where '+' is the delimiter.
I have: NSString *promise = @thereAreOtherWorldsThanThese; which I'm trying to transform into the string:
I have a date in string like NSString Date = Dec 21 2011; I
If I create a String with [NSString StringWithFormat], do I have to [retain] it?
i have a string declare as such NSString *str = [[NSString alloc] initWithFormat:@I require
I have a string value. NSString *myString = @Latitude:-31.9504140#Longitude:115.8606040; How can I retrieve the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.