Yo,
I am fairly new to C# and I'm making a small text based console RPG game just for practice and I was wondering if there was anyway I could make something similar to this:
Here's an example .csv if I didn't really explain it well:
"charactername", "password123", "health", "level"
"Oswald", "498562a", "100", "4"
"Hammerfist", "98457813", "77", "6"
So just for the sake of clarity, this is what I'm thinking:
Is there a way to do this? Am I overlooking a simple solution? Or should I try and go about it a different way? I'm just don't want to hard code the values into a Dictionary or List or Array or whatever. I'm not looking for security at this stage either, it's just for practice and fun.
Thanks in advance! Let me know if you need a better understanding of what I'm trying to do and I'll try to explain the best I can.
There are two ways to go about reading csv
Just like standard text file, line by line. Then parse your line into array of columns and get your values
Using Microsoft.ACE.OLEDB.version
OleDbconnection connection = new OleDbConnection(); connection.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Documents\\file.csv;Extended Properties=\\"Text;HDR=Yes;FORMAT=Delimited\\"";
This way you can load DataTable
on the start of your app and query this table just like Sql database.
notice : HDR=Yes means that first row is a header row
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.