C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
7,514 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi All,
I have textfile contain 3 lines.
// line1 3518,4745
// line2 9019,0396
// line3 4753,9196
TODO, line1 3518,4745 put in Data2.
line2 9019,0396 put in Data3'
line3 4753,9196 put in Data4'
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Str3Number_
{
public partial class Form1 : Form
{
List<string> Data1 = new List<string>();
List<string> Data2 = new List<string>();
List<string> Data3 = new List<string>();
List<string> Data4 = new List<string>();
List<string> Data5 = new List<string>();
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
foreach (var s in File.ReadLines(@"C:\Users\family\Documents\3digit_one.txt"))
{
listBox1.Items.Add(s);
Data1.Add(s);
}
}
Thank AgaveJoe, I understand it just for file layout. I thinking it could use some like "Console.writeline" or "Readline ?" then put in List..
You response is not clear but I'm fairly sure you have no idea what a file layout is...
Reading and parsing a file is an extremely common programming task. Typically the file has a specified file layout similar to records in a table. The file layout is required otherwise there is no way to determine where the fields and records begin and end.
Your example file contents looks like a comma separated values (CSV) file. CSV files must come with a documentation that describes each field. These are items like the field names and types. Without this information it is impossible to understand the data.
Without context, your proposed solution is a poor approach to a very common programming problem.
I think I'm doing wrong.
It true come from CSV file.
Thank a lot.
Thank AgqveJoe for your Explanation.
Thank for Explanation.
@MiPakTeh , is any update? Do you have time to check if my answer works for you?
Sign in to comment
@MiPakTeh , Welcome to Microsoft Q&A, based on your description, you want to load the text file into 3 different list.
I suggest that you could create a list of list<string>, here is a code example you could refer to.
code.txt
Result:
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Sign in to comment
0 additional answers
Sort by: Most helpful