C # - What is the best way to write text to a file from an array of strings

Group

I am looking for new and interesting ways to write an array of strings to a .txt file. -This file will be overwritten every time it is called and saved. -The file name will be dynamic enough that .exe will know which line goes there.

For instance:

 ~/someFile.exe "fileName" "string|string|string|"

-In this example, someFile.exe is called to write lines to this "file_name".

Any suggestions?

Chad

+3
source share
4 answers

You can use the File.WriteAllLines method :

public class Program
{
    static void Main(string[] args)
    {
        File.WriteAllLines(
            args[0], 
            args[1].Split(new [] { '|' }, StringSplitOptions.RemoveEmptyEntries)
        );
    }
}

And then call: someFile.exe "fileName" "string|string|string|"

+7
source

StreamWriter.WriteLine.
, , :

0

, " , .exe , ?"

, , "" . , , ?: -)

0

Source: https://habr.com/ru/post/1764204/


All Articles