The following code will display the "Middle of the Input string using C#.net.
In case Input Like this:
public static string Midstring(string inputString)
{
int length = inputString.Length;
Double midvalue = length /2;
if (length % 2 != 0)
{
int mid = Convert.ToInt32(midvalue);
char[] InputString = inputString.ToCharArray();
Reslt = InputString[mid].ToString();
}
else
{
Reslt = "Sorry, we can't give the Result";
}
return Reslt;
}
{
int length = inputString.Length;
Double midvalue = length /2;
if (length % 2 != 0)
{
int mid = Convert.ToInt32(midvalue);
char[] InputString = inputString.ToCharArray();
Reslt = InputString[mid].ToString();
}
else
{
Reslt = "Sorry, we can't give the Result";
}
return Reslt;
}
Input: string Result = Midstring("Lakshmi");
MessageBox.Show("Result:" + " " + Result.ToUpper() + " " + " is a Middle of the Value");
Output: Result : S is a Middle of the Value.MessageBox.Show("Result:" + " " + Result.ToUpper() + " " + " is a Middle of the Value");
In case Input Like this:
Input: string Result = Midstring("Like");
MessageBox.Show("Result:" + " " + Result.ToUpper() + " " + " is a Middle of the Value");
Output: Result : Sorry, we can't give the Result. MessageBox.Show("Result:" + " " + Result.ToUpper() + " " + " is a Middle of the Value");