public class StringManipulation
{
string s1 = "hamid";
String s2 = "Mahfooz";
public static string ReverseString(string s1)
{
if (s1.Length <= 1)
return s1;
return ReverseString(s1.Substring(1)) + s1[0];
}
public static void ReverseString1(string s1)
{
string Revstr = ""; //for storing string value
int Length; //for counting lenght of given string
Length = s1.Length - 1; //storing the length of given string
while (Length >= 0) //loops the given string length
{
Revstr = Revstr + s1[Length]; //performimg a reverse string according to length of given string
Length--;
}
Console.WriteLine("Reverse String Is {0}", Revstr); // displaying output to user
}
}
class StringTest
{
public static string ReverseString(string s)
{
string tmp = string.Empty;
for (int i = s.Length - 1; i >= 0; i--)
{
tmp += s[i].ToString();
}
return tmp;
}
}
No comments:
Post a Comment