Sample code for substring with out using string functions in c#.

Posted by Sekar.C under C# on 4/29/2012 | Points: 10 | Views : 2133 | Status : [Member] | Replies : 2
Hi,
Sample code for substring with out using string functions in c#.

Regards
Sekar.c

Regards
Sekar.c



Responses

Posted by: Niladri.Biswas on: 4/30/2012 [Member] Platinum | Points: 25

Up
0
Down
I donot understand why you need this; however, here is my attempt

private static string CustomSubstring(int startIndex)

{
string input = "Hello! how r u?";
return input.ToCharArray().Skip(startIndex).Aggregate("", (a, b) => a + b);
}

private static string CustomSubstring(int startIndex, int length)
{
string input = "Hello! how r u?";
return input.ToCharArray().Skip(startIndex).Take(length).Aggregate("", (a, b) => a + b);
}


Best Regards,
Niladri Biswas

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Niladri.Biswas on: 4/30/2012 [Member] Platinum | Points: 25

Up
0
Down
Even this will do the same

private static string CustomSubstring(int startIndex)

{
string input = "Hello! how r u?";
int len = input.Length;
string result = string.Empty;

for (int i = 0; i < len; i++)
{
if(i >=startIndex)
result += input[i];
}
return result;
}

private static string CustomSubstring(int startIndex, int length)
{
string input = "Hello! how r u?";
int len = input.Length;
string result = string.Empty;

for (int i = 0; i < len; i++)
{
if (i >= startIndex && i <= startIndex + length)
result += input[i];
}
return result;
}


Best Regards,
Niladri Biswas

Sekar.C, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response