C# – Save a list of strings to a file

The simplest way to save a list of strings to a file is to use File.WriteAllLines(). This creates (or overwrites) the specified file and writes each string on a new line. The resulting file looks like this: Note: Showing non-printable newline characters \r\n for clarity. Specifying the separator character What if you want to separate … Read more

C# – Join strings with a separator, ignoring nulls and empty strings

Normally when you want to join strings using a separator, you’d use string.Join(). However, the problem with string.Join() is it doesn’t ignore nulls or empty strings. Take a look at the following examples: If you want to filter out nulls and empty strings, you can filter the list of strings yourself and pass it into … Read more