I have opened a .CSV file in RichTextBox.I added every line's first word to CombobBox items. I want to edit this a specific word and then save it back to the File.
This is how i open the file to richTextBox1.
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "Csv files (.csv)|*.csv";
ofd.Title = "Open a file...";
if (ofd.ShowDialog() == DialogResult.OK)
{
StreamReader sr = new StreamReader(ofd.FileName);
richTextBox1.Text = sr.ReadToEnd();
}
Now i want a Button that finds my comboBox1.Text in richTextBox and replace it with txtbox.Text.
My button looks like this:
private void button1_Click(object sender, EventArgs e)
{
using (TextReader reader = new StringReader(richTextBox1.Text))
{
string str = reader.ReadToEnd();
string cbtxt = comboBox1.Text;
string tbtxt = txtbox.Text;
str = str.Replace(cbtxt, tbtxt);
}
}
I would add the method to the end of this button that would save back the text from richTextBox to my .CSV file but this replace method doesnt replace anything in my richTextBox.
My .CSV file (in richTextBox) looks like this:
somestring,somenumber,somespecialcharacters;
somestring2,somenumber2,somespecialcharacters2;
It has about 50 lines,and my combobox is filled with the first words of every line like: "somestring" "somestring2". When i click on somestring (then its my combobox.text) then i write "newstring" to my txtbox.text. When i click my button it should find comboBox.text in richtxt and replace it with my txtbox.text.
Any ideas why it doesnt work?