C# write list string to file


















What if you want to separate each string with a comma or some other separator character of your choice , instead of writing each string on a new line? To do that, you can join the strings and specify the separator character you want to use, and then use File. To read the strings from a file into a list, you can use File.

ReadAllLines , which returns a string array. To get the strings back into a list, you have to read the file and split the string with the separator character. Notice that this is reading the entire file. WriteAllLines — Corak. Add a comment. Active Oldest Votes. Add value ; System. Improve this answer. Thanks that has fixed it, I know it needs to be refactored and cleaner but for now it works so I am happy : — RyanK.

RyanK Be sure to upvote Tim's answer as well the up arrow on the left side of his post. ReadLines path. StartsWith startPattern. Substring startPattern. ToList ; This will create and fill the list. Intersect lstStore ; File. Tim Schmelter Tim Schmelter k 64 64 gold badges silver badges bronze badges. The C example requires C 7. The following example shows how to write text to a new file and append new lines of text to the same file using the File class.

If the path you provide to the WriteAllText method already exists, the file is overwritten. Skip to main content. This browser is no longer supported. Download Microsoft Edge More info. Contents Exit focus mode. Something like: C. Posted Feb pm Richard MacCutchan. Add your solution here. OK Paste as. Treat my content as plain text, not as HTML.

Existing Members Sign in to your account. This email is in use. Do you need your password? Submit your solution! When answering a question please: Read the question carefully. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem.

Insults are not welcome. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.



0コメント

  • 1000 / 1000