How to find Mid Character for dynamic Input . For example i am giving "Apple" Means Display
Result: P.
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Satyapriya NayakRank #47 · 31.5K reputationPosted Nov 23, 2013, 1:46 AM EST
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace Middle_chracter
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public static string Result;
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();
Result = InputString[mid].ToString();
}
else
{
Result = "Sorry, we can't give the Result";
}
return Result;
}
private void btn_middle_char_Click(object sender, EventArgs e)
{
//string Result = Midstring(textBox1.Text);
string Result = Midstring("Apple");
MessageBox.Show("Result:" + " " + Result.ToUpper() + " " + " is middle character in the given string");
}
}
}
VulpesRank #55 · 29.2K reputationPosted Nov 23, 2013, 7:14 AM EST
In the case of input of even length(e.g. abcd), the mid character is taken as the first of the two middle characters (i.e. b):