• river1 - Monday, December 18, 2017 7:46 AM

    Sorry. My bad:

    Filenameonly2 = (line.Replace(" ", " "));

    Filenameonly2 = (Filenameonly2.Replace(" ", "_"));

    But it still not works...

    I still get

    16_DIVIDENDS_SAME_DAY_______D_5011R.08_______20171128

    Initially I was getting

    16_DIVIDENDS_SAME_DAY________________________D_5011R.08_____________________20171128

    Now I am getting:

    16_DIVIDENDS_SAME_DAY_______D_5011R.08_______20171128

    Your logic for replacing multiple spaces is flawed. Take a read here, for example.

    If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.