Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Cocoa Touch, substrings

  • 06-05-2008 9:01am
    #1
    Registered Users, Registered Users 2 Posts: 72 ✭✭


    Hi all..
    I'm a beginner to cocoa touch and i was wondering if anyone could help me out.
    Does anyone know how to split a string in half in cocoa touch?

    what im looking to do is, say if i have a string with value 'abcdefghijkl'
    i want to be able to split it up into 2 strings to that i will have
    string1 = abcdef and string2 = ghijkl

    Hope this makes sence and any help would be great.


    cheers...


Comments

  • Registered Users, Registered Users 2 Posts: 21,263 ✭✭✭✭Eoin


    Hi all..
    I'm a beginner to cocoa touch and i was wondering if anyone could help me out.
    Does anyone know how to split a string in half in cocoa touch?

    what im looking to do is, say if i have a string with value 'abcdefghijkl'
    i want to be able to split it up into 2 strings to that i will have
    string1 = abcdef and string2 = ghijkl

    Hope this makes sence and any help would be great.


    cheers...

    I don't know what cocoa touch is, but I presume it has standard text functions?

    A substring function should take the start position and the length of the string as parameters.

    So, first you need to get the length of the first string. You'll have to decide how you want to handle if it's an uneven length. Dividing this figure by two, will obviously give you the point where you want to split the strings.

    The first half of the string will start at 1 or 0 (depending on the programming language) and will end at the halfway point that you've just gotten above. You may also have to add or subtract 1 from the halfway point, as this is all off the top of my head.

    To use pseudo code:
    
    string1 = "abcdefghijkl";
    stringLength = string1.Length;
    
    firstHalf = string1.substr(0, stringLength / 2);
    

    This will give you enough to work out the second half of the string.


  • Closed Accounts Posts: 8,866 ✭✭✭Adam




  • Registered Users, Registered Users 2 Posts: 981 ✭✭✭fasty


    eoin_s wrote: »
    I don't know what cocoa touch is, but I presume it has standard text functions?

    I'm assuming he's talking about the api for iPhones which is basically Cocoa.

    The op will need to look at substring/splitting functions for NSString I'd imagine...

    http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSString_Class/Reference/NSString.html


Advertisement