String Question

Discussion in 'iPhone Tips, Help and Troubleshooting' started by dareuhl, May 24, 2008.

  1. dareuhl macrumors newbie

    May 24, 2008
    Im trying to figure how to do this, which is written in C#, in objective C....

    public static string Mid(string param,int startIndex)
    //start at the specified index and return all characters after it
    //and assign it to a variable
    string result = param.Substring(startIndex);
    //return the result of the operation
    return result;

    thanks in advance

    basically i want to get all characters after a specified character.
  2. pranavss11 macrumors 6502

    Dec 29, 2007
    San Jose
    The code looks fine I think, but I could be wrong its 4.20 AM. So whats the problem? Is the left to right thing?

    //assign a value to our string
    string myString = "This is a string";
    //get 4 characters starting from the left
    //get 6 characters starting from the right
    //get 4 characters starting at index 5 of the string
    //get the characters from index 5 up to the end of the string
    //display the result to the screen Console.ReadLine();
  3. mysticwhiskey macrumors newbie

    Mar 31, 2008

    I think -[NSString substringFromIndex] will do what you want:

    NSString* string1 = @"ABCDEF";
    NSString* string2 = [string1 substringFromIndex:3];    // string2 should be "DEF"
    I'm not at my Mac now, so I can't test this. Let us know if it works.

    BTW: This thread should be in the programming section, not the iPhone one... ;)

Share This Page