Hi,
I'm trying to insert a number between a string.
For e.g. : If I have a string like "C23H24N1O" or "CHAl"
Then it should be "C23H24N1O1" or "C1H1Al1"
If a capital letter doesn't carry any numerical then it should insert "1" next to it
If a capital letter carry a small letter (for e.g. "Na") and if this small letter doesn't carry any number then it should insert "1" (for e.g. "Na1")
If these carry numbers then no alterations should be made.
private void button17_Click(object sender, EventArgs e)
{
textBox5.Clear();
for (int i = 0; i < textBox4.Text.Length; i++)
{
if ((textBox4.Text[i] >= 'A') && (textBox4.Text[i] <= 'Z'))
{
textBox5.AppendText(textBox4.Text[i].ToString());
if ((textBox4.Text[i + 1] >= 'A') && (textBox4.Text[i + 1] <= 'Z') || (textBox4.Text[i + 1] >= ' '))
{
try
{
if ((textBox4.Text[i + 1] >= 'a') && (textBox4.Text[i + 1] <= 'z'))
{
if ((Convert.ToInt32(textBox4.Text[i + 2]) >= 1) && ((Convert.ToInt32(textBox4.Text[i + 2]) <= 9)))
{
textBox5.AppendText(textBox4.Text[i + 1].ToString() + textBox4.Text[i + 2].ToString());
}
else
{
textBox5.AppendText(textBox4.Text[i + 1].ToString() + "1");
}
}
else if ((textBox4.Text[i + 1] >= 'A') && (textBox4.Text[i + 1] <= 'Z'))
{
if ((textBox4.Text[i + 2] >= 'a') && (textBox4.Text[i + 2] <= 'z'))
{
textBox5.AppendText(textBox4.Text[i + 2] + "1");
}
else
{
textBox5.AppendText("1");
}
}
}
catch { }
}
else
{
textBox5.AppendText(textBox4.Text[i+1].ToString());
}
}
else
{
textBox5.AppendText(textBox4.Text[i].ToString());
}
}
}
This this what I have tried but still there is some functionality missing.
Please help me..
regards,
Srik