NSRange

Discussion in 'Mac Programming' started by varsis, Sep 15, 2008.

  1. varsis
    Expand Collapse
    macrumors regular

    Joined:
    Nov 30, 2005
    #1
    Here is what I am trying to do,

    I retrieve two NSRanges one which comes from a document and one that is in the application I want to know if the Ranges are overlapping in anyway if they are. Also get the portion of the overlapping range.
     
  2. robbieduncan
    Expand Collapse
    Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    NSRange is just a C struct as described in this document. You can simply retrieve the location and length from each range and work out if they overlap.

    There is also the very handy NSIntersectionRange function which will return a new range representing the intersection (or overlap). This basically does exactly what you want.
     
  3. varsis
    Expand Collapse
    thread starter macrumors regular

    Joined:
    Nov 30, 2005
    #3
    Thanks! Got it working...
     

Share This Page