المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : Replacing items within a string



C# Programming
03-06-2013, 10:30 AM
Hello CP!

Alright, I thought this would be simple, but apparently I don't know what I am doing. I have a Rich Text Box that populates upon form load. There are fields that are meant to be updated by text boxes on this form. Here's a snip of the form_load:

private void Form1_Load(object sender, EventArgs e) { string cifTime = timeCIF.Text; string chkCIF = "N"; emailBody.Text = "Example\nCIF = " + chkCIF + "\nTIME = " + timeCIF.Text; } So what happens here is the form opens and populates a rich text box with:

Example
CIF = N
TIME =

Now, what I need to have a button do is update just the items I have defined, in this case chkCIF (a check box) and timeCIF.Text (a textbox). I have a button that's called update, and here's what it looks like.

private void updateButton_Click(object sender, EventArgs e) { //There is a combo box on this form and example is the first option if (comboInst.Text == "Example") { //Here is where the check box verification is, if it is true it should change the N to Y if (checkCIF.Checked == true) { //This part needs to update the current contents of the email body. Obviously, this isn't working for me so I commented out some examples I tried... //string s = emailBody.Text; //string chkCIF = "Y"; //s = s.Replace("N", chkCIF); string theString = emailBody.Text; theString.Remove(3, 2).Insert(3, "Y"); } }
And there you have it. I just need to be able to update certain defined words from a string with a click of a button. Thanks in advance http://www.barakasoft.com/script/Forums/Images/smiley_smile.gif