You have to use String.Split
string[] aux;
double resultado;
if (textBox1.Text.Contains("/"))
{
aux = textBox1.Text.Split(new char[] { '/' }, 2);
resultado = double.Parse(aux[0]) / double.Parse(aux[1]);
}
else
{
resultado = double.Parse(textBox1.Text);
}
MessageBox.Show(resultado.ToString());
EDIT: In the case that you need to be able to enter more complex fractions like 3/4/6 you can do the following ..
string[] aux;
double resultado=0;
if (textBox1.Text.Contains("/"))
{
aux = textBox1.Text.Split(new char[] { '/' }, textBox1.Text.Length-1);
resultado = double.Parse(aux[0]);
foreach(string numero in aux.Skip(1))
{
resultado /= double.Parse(numero);
}
}
else
{
resultado = double.Parse(textBox1.Text);
}
MessageBox.Show(resultado.ToString());
It is possible that there is a simpler way to solve it, but it is the first thing that occurred to me, greetings!