Comparing characters in a string?

Discussion in 'Mac Programming' started by Simplicated, Jan 4, 2009.

  1. Simplicated macrumors 65816

    Simplicated

    Joined:
    Sep 20, 2008
    Location:
    Waterloo, Ontario, Canada
    #1
    Hello, I have two strings here

    Code:
    ABCDEFGH
    and another one

    Code:
    AACCEEGG
    I want to compare them, one character at a time.

    Is there any ways to achieve this in Obj-C?

    Thank you very much.
     
  2. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #2
    Sure, have a look at NSString's characterAtIndex: method, all you need is an int to keep track of the index as you walk down the string (check the length of both strings first if you can't be sure they'll be the same). If you have C strings instead of Unicode NSStrings, you can easily do it using C pointers and directly comparing the value of each character value.
     

Share This Page