.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Home >> Articles >> C# >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Middle of the Input String in C#.net

Posted By:Narayanan       Posted Date: March 13, 2012    Points: 25    Category: C#    URL: http://www.dotnetspark.com  

The following code will display the "Middle of the Input string using C#.net.

    #region Mid of the String
        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();
                Reslt = "Sorry, we can't give the Result";
            return Reslt;

      #endregion Mid of the String

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.
 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend