| | |
notepad
![]() |
1
#2 Nov 11th, 2009
Hi Sidd. welcome here!
Try this:
Try this:
c# Syntax (Toggle Plain Text)
using (StreamReader sr = new StreamReader ("myfile.dat")) { string s = sr.ReadLine(); //etc. }
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Make love, no war. Cave ab homine unius libri.
Danny
0
#3 Nov 11th, 2009
C# Syntax (Toggle Plain Text)
List<string> mylines = new List<string>(); using (StreamReader sr = new StreamReader("myfile.dat")) { while (sr.ReadLine() != null) { mylines.Add(sr.ReadLine()); } }
Yeah, That should work. assuming each line is a separate value, otherwise you will need to load it all to memory as a string and split it to an array using the delimiter. Post back if you need more help.
•
•
Join Date: Oct 2009
Posts: 30
Reputation:
Solved Threads: 3
0
#4 Nov 15th, 2009
Just in case, here is a method to read from a CSV or delimiter. It returns data to its caller.
C# Syntax (Toggle Plain Text)
static void Main(string[] args) { List<string> columns; List<Dictionary<string, string>> myData = GetData(out columns); foreach (string column in columns) { Console.Write("{0,-20}", column); } Console.WriteLine(); foreach (Dictionary<string, string> row in myData) { foreach (string column in columns) { Console.Write("{0, -20}", row[column]); } Console.WriteLine(); } Console.ReadKey(); } public static List<Dictionary<string, string>> GetData(out List<string> columns) { string strLine; string[] strArray; char[] charArray = new char[] { ',' }; List<Dictionary<string, string>> data = new List<Dictionary<string, string>>(); columns = new List<string>(); try { StreamReader sr = new StreamReader(new FileStream("C:\\TECHDATA.txt", FileMode.Open)); strLine = sr.ReadLine(); strArray = strLine.Split(charArray); for (int x = 0; x <= strArray.GetUpperBound(0); x++) { columns.Add(strArray[x]); } strLine = sr.ReadLine(); while (strLine != null) { strArray = strLine.Split(charArray); Dictionary<string, string> dataRow = new Dictionary<string, string>(); for (int x = 0; x <= strArray.GetUpperBound(0); x++) { dataRow.Add(columns[x], strArray[x]); } data.Add(dataRow); strLine = sr.ReadLine(); } sr.Dispose(); return data; } catch (IOException ex) { Console.WriteLine(ex.Message); } return data; }
![]() |
Similar Threads
- Notepad wont load (Windows NT / 2000 / XP)
- Notepad gone?? (Windows NT / 2000 / XP)
- reinstalling notepad in windows 2000 pro? (Windows NT / 2000 / XP)
- Notepad VS. Something Else (Java)
Other Threads in the C# Forum
- Previous Thread: Microsoft XNA Game Studio 2.0
- Next Thread: Disabling menuStrip
Views: 566 | Replies: 3
| Thread Tools | Search this Thread |
Tag cloud for C#
.net 2d access algorithm application array asp.net assembly bitmap box button c# chat check checkbox class code color combo combobox control conversion csharp custom data database datagrid datagridview dataset degrees directshow display dll drawing event excel exception file form format forms ftp function gcd gdi+ graphics image index input install internet label list listbox login math mysql notepad object office operator outlook2007 picturebox pixel print problem programming query remote remoting resource resourcefile richtextbox saving search server socket sql sql-server statistics stream string text textbox thread threading time timer treeview update validation vc++ view visual webbrowser webcam windows winforms wpf xml






