hello
i am elaborating a program that will read a file, modify it and sort its contents(if the contents are integers sort them into a listbox)
char letra = ' ';
string cad;
char[] numbers = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', ' ' };
private void button2_Click(object sender, EventArgs e)
{
StreamReader sr = new StreamReader(textBox1.Text);
richTextBox1.Text = sr.ReadToEnd();
sr.Close();
for (int i = 0; i < richTextBox1.Text.Length; i++)
{
letra = richTextBox1.Text[i];
if (Array.IndexOf(letra, numbers) != -1)
{
cad = cad + letra;
listBox1.Items.Add(cad);
}
}
}
i think i have my condition all mixed up....can someone help me out with this?
2 replies to this topic
#1
Posted 29 August 2011 - 11:11 PM
|
|
|
#2
Posted 30 August 2011 - 11:14 AM
Hi Cesarg! Glad to see you made it out of the blogs section. :)
You have a few problems with your code. This seems to be working.
Good luck ~ Committed.
You have a few problems with your code. This seems to be working.
char letra = ' ';
string cad;
char[] numbers = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', ' ' };
private void button1_Click(object sender, EventArgs e)
{
[COLOR=#006400]//StreamReader sr = new StreamReader(textBox1.Text); Why are you using a stream reader to place the textBox.Text into the richTextBox?
//sr.ReadToEnd(textBox1.Text);
//richTextBox1.Text = sr.ReadToEnd();
//sr.Close();[/COLOR]
richTextBox1.Text = textBox1.Text()
for (int i = 0; i < richtextBox1.Text.Length; i++)
{
letra = richtextBox1.Text[i];
if (numbers.Contains(Convert.ToChar(letra)))[COLOR=#006400]//Convert letra to char then see if it matches a value.[/COLOR]
{
cad += letra;[COLOR=#006400]// cad = cad call should be avoided.[/COLOR]
listBox1.Items.Add(cad);
}
}
}
Good luck ~ Committed.
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.
Science is only an educated theory, which we cannot disprove.
#3
Posted 30 August 2011 - 03:16 PM
thank you! and it did tale me a while to figure out the forum. ive never been involved in a programming forum before but im glad i integrated myself into it.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account

Back to top









