Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dareuhl

macrumors newbie
Original poster
May 24, 2008
1
0
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.
 

pranavss11

macrumors 6502
Dec 29, 2007
360
0
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
Console.WriteLine(Left(myString,4));
//get 6 characters starting from the right
Console.WriteLine(Right(myString,6));
//get 4 characters starting at index 5 of the string
Console.WriteLine(Mid(myString,5,4));
//get the characters from index 5 up to the end of the string
Console.WriteLine(Mid(myString,5));
//display the result to the screen Console.ReadLine();
 

mysticwhiskey

macrumors newbie
Mar 31, 2008
25
0
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.

Hi,

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

Code:
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... ;)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.