concatenate two integers

Discussion in 'iOS Programming' started by duny, Jul 30, 2009.

  1. duny macrumors newbie

    duny

    Joined:
    Sep 21, 2008
    Location:
    H-Town
    #1
    How do I concatenate two integers together, say i have 2 and 30 and want to make 230.
     
  2. PhoneyDeveloper macrumors 68030

    PhoneyDeveloper

    Joined:
    Sep 2, 2008
    #2
    Do you want the result to be an integer or a string?

    If a string, look at stringWithFormat.
     
  3. drivefast macrumors regular

    Joined:
    Mar 13, 2008
  4. LTX macrumors regular

    LTX

    Joined:
    Dec 25, 2008
    Location:
    Vancouver, BC, Canada
    #4
    That's only going to work for a very small set of number pairs. It wouldn't, for example, work with 300 and 999 to make 300999. You would get 30999.
     
  5. mccannmarc macrumors 6502

    mccannmarc

    Joined:
    Aug 15, 2008
    Location:
    Manchester, UK
    #5
    You would have to make the 2 values NSString's and concatenate them into one NSString. You can then get the int value from the string using the NSString's integerValue getter
     
  6. Troglodyte macrumors member

    Joined:
    Jul 2, 2009
    #6
    Code:
    int combinedInt=[[NSString stringWithFormat:@"%i%i", int1, int2] intValue];
    
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    I think before we spit out any more solutions we need the OP to come back and clarify what it is that they want.
     

Share This Page