h1.post-title { color:orange; font-family:verdana,Arial; font-weight:bold; padding-bottom:5px; text-shadow:#64665b 0px 1px 1px; font-size:32px; } -->

Pages

Get Middle of the Input String in C#.net

The following code will display the "Middle of the Input string using C#.net.
    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;
    }


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.
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.