none
Removing spaces in ftp txt file RRS feed

  • Question

  • Hi, i need some code like that

                int count = listBox2.Items.Count;
                for (int i = count - 1; i >= 0; i--)
                {
                    if (listBox2.Items[i].ToString() == " ")
                    {
                        listBox2.Items.RemoveAt(i);
                    }
                }
    but just to ftp txt file.
    Wednesday, December 5, 2018 8:04 PM

All replies

  • We need some more information, Noam, or at least something along the lines of what you're trying to accomplish. Do you want to remove lines in your txt file that have only spaces? Does your txt file actually have lines? You may be able to just do a string.Replace() to replace all spaces, with an empty string. Again, without more details, I can't be more specific ...

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Wednesday, December 5, 2018 8:53 PM
    Moderator
  • I need that code will be can used in a txt file on ftp server...

    again the code:

                int count = listBox2.Items.Count;
                for (int i = count - 1; i >= 0; i--)
                {
                    if (listBox2.Items[i].ToString() == " ")
                    {
                        listBox2.Items.RemoveAt(i);
                    }
                }

    Wednesday, December 5, 2018 9:06 PM
  • Sorry, that doesn't help explain what you want!  =0(

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Wednesday, December 5, 2018 9:11 PM
    Moderator
  • OK, code for removing spaces in a text file on ftp server...?

    Helps?

    Wednesday, December 5, 2018 9:17 PM
  • Can you first retrieve the text file from the ftp server? Off the top of my head, I don't know if there's anything special that has to be done to read a file from an ftp server. Maybe it's as simple as this:

    string txt = File.ReadAllText(PathAndFileName);
    txt.Replace(' ', '');
    // and to write it back
    File.WriteAllText(PathAndFileName, txt);

    Or this:

    string[] txtLines = File.ReadAllLines(PathAndFileName);
    List<string> lstLines = txtLines.ToList(); // I think this .ToList() will work, haven't test it
    for (int i = lstLines.Count - 1; i >= 0; i--)
    {
        if (string.IsNullOrEmpty(lstLines[i]))
            lstLines.RemoveAt[i];
    }
    // and to write it back
    File.WriteAllLines(PathAndFileName, lstLines);

    If there is more that has to be done to read/write to the FTP, you'll have to research that more yourself. I don't know right now and don't have the time to Google for an answer at the moment.

    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Wednesday, December 5, 2018 11:17 PM
    Moderator
  • OK, code for removing spaces in a text file on ftp server...?


    Isn't this a similar operation to your previously answered thread?

    Replace a text in ftp txt
    https://social.msdn.microsoft.com/Forums/vstudio/en-US/eb8effa4-3018-41ac-8ceb-f6c345da5806/replace-a-text-in-ftp-txt?forum=csharpgeneral

    - Wayne

    Wednesday, December 5, 2018 11:38 PM
  • Can you first retrieve the text file from the ftp server? Off the top of my head, I don't know if there's anything special that has to be done to read a file from an ftp server. Maybe it's as simple as this:

    string txt = File.ReadAllText(PathAndFileName);
    txt.Replace(' ', '');
    // and to write it back
    File.WriteAllText(PathAndFileName, txt);

    Or this:

    string[] txtLines = File.ReadAllLines(PathAndFileName);
    List<string> lstLines = txtLines.ToList(); // I think this .ToList() will work, haven't test it
    for (int i = lstLines.Count - 1; i >= 0; i--)
    {
        if (string.IsNullOrEmpty(lstLines[i]))
            lstLines.RemoveAt[i];
    }
    // and to write it back
    File.WriteAllLines(PathAndFileName, lstLines);

    If there is more that has to be done to read/write to the FTP, you'll have to research that more yourself. I don't know right now and don't have the time to Google for an answer at the moment.

    ~~Bonnie DeWitt [C# <strike>MVP</strike>]

    At manager of all mvps: this forum member, is once more, trolling this forum with rubbish# code.

    As usual, its code compiles (i.e., no errors), but it doesn't do what was planned to do.

    See the code where string.IsNullOrEmpty() is used: this code will not eliminate the lines that contain white spaces only(!), a required by OP.

    I'd like to remind, that this forum member has posted in the last 3 weeks:

        1) the rubbish# concept that default access specifier for classes, is private!
        2) the 2nd most rubbish# code of the current yearly semester.

        3) and, unbelievably, the 1st most rubbish# code of the current yearly semester.It has systematically troll'ed this forum, with similar and even worse, posts.

    Thursday, December 6, 2018 3:41 AM
  • >>See the code where string.IsNullOrEmpty()is used: this code will not eliminate the lines that contain white spaces only(!), a required by OP.<<

    You're right, I should have said to use string.IsNullOrWhiteSpace() … but you don't have to be so obnoxious about it with all your talk of rubbish# code. And talk about trolling … you go and look up some of my previous posts and complain about them here too! Why don't you just go away …  =0(


    ~~Bonnie DeWitt [C# MVP]

    http://geek-goddess-bonnie.blogspot.com

    Thursday, December 6, 2018 2:57 PM
    Moderator
  • >> HELPS?

    No.

    You've had some replies here that have gone off into the weeds, and the reason is that you are not asking your question in a precise way.  That forces people to try to read between the lines and guess your intention.

    Are you trying to write a program to fetch a file from an FTP server, remove the spaces, and store the result in a string?  Or do you want to save the stripped result in a text file?

    The question you asked implies that you want to change the file as it is stored on the server.  That can also be done, assuming you have "write" permission.  You can read the file, remove the blanks, and send it back to the server.  But that seems like an unusual need.

    Is the FTP server one that you control?  If so, you could write a program that runs ON THAT SERVER to remove spaces from files.  In that case, FTP wouldn't be involved at all.

    So, as you can see, I've now come up with 4 completely different interpretations of what you want.  Only YOU can clear this up, by telling us exactly what you want.  Describe the process in words.


    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    Friday, December 7, 2018 8:30 PM

  • Why don't you just go away …  =0(


    ~~Bonnie DeWitt [C# <strike>MVP</strike>]

    We got a deal!

    Use your special credential, and ban my account: definitely, I won't come back. 

    If you don't succeed, try asking someone with more powerful credential.

    If you fail again, it means they are not satisfied with you, and your colleagues, that are making this forum sink.

    But, yes, we got a deal!

    Saturday, December 8, 2018 7:02 AM