-2

I have an application that reads from a file and inserts the contents of the file into a table. I split the data up into substrings respective of their fields. For one of the fields, I need to replace a character (F) with a 0. I have tried this, however it isn't working (F is still being inserted).

string[] mylines02 =   System.IO.File.ReadAllLines(@"C:\\BillingExport\\IMPORTS\\ACNTBILL.ALL.TYPE02.FRMATED.txt");

List<ACCOUNT_BILL_PLANS> table2_1Input = new List<ACCOUNT_BILL_PLANS>();
ACCOUNT_BILL_PLANS table2_1 = new ACCOUNT_BILL_PLANS();

for (int i = 0; i < mylines02.Length; i++)
{
    var fixf_over = mylines02[i].Substring(64, 3).Trim().ToString();
    if (fixf_over.Contains("F"))
    {
        fixf_over.Replace("F", "0"); 
    }

    table2_1Input.Add(table2_1);

    using (SqlCommand cmd72 = new SqlCommand(insertString72, _cond2))
    {
        cmd72.Parameters.Add("@OVERPAYMENT_LIMIT", SqlDbType.NChar);

        cmd72.Parameters["@OVERPAYMENT_LIMIT"].Value = fixf_over;

        cmd72.ExecuteNonQuery();
        _cond2.Close();
    }
user247702
  • 23,641
  • 15
  • 110
  • 157
Bob Francis
  • 47
  • 1
  • 1
  • 8
  • 2
    `fixf_over.Replace("F", "0");` will not modify the original string it will return a new string so assign it back like `fix_over = fixf_over.Replace("F", "0");` – Habib Oct 22 '14 at 14:17
  • Also see [Why .NET String is immutable?](http://stackoverflow.com/q/2365272/961113) – Habib Oct 22 '14 at 14:18

2 Answers2

0

Apply it to the variable?

fixf_over = fixf_over.Replace("F", "0"); 
Allmighty
  • 1,499
  • 12
  • 19
0

String.Replace does no inplace update, but instead returns a string that has those replacements you are looking for:

fixf_over = fixf_over.Replace("F", "0"); 
nvoigt
  • 75,013
  • 26
  • 93
  • 142