| | |
cast text file to an array
Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Oct 2007
Posts: 10
Reputation:
Solved Threads: 0
Newbie question;
How do I cast a text file to an array, after the file is read using StreamReader?
I have read many threads, code etc but I really need my hand held here, I just dont get it (especially using windows forms)...this is part of an assignment.... I've been going around in circle's over this for the last week...and I'm a desperate now.
Your help would be appreciated.
this code works as it is, but I don't have an array (not an arraylist cause no manipulation required)
How do I cast a text file to an array, after the file is read using StreamReader?
I have read many threads, code etc but I really need my hand held here, I just dont get it (especially using windows forms)...this is part of an assignment.... I've been going around in circle's over this for the last week...and I'm a desperate now.
Your help would be appreciated.
this code works as it is, but I don't have an array (not an arraylist cause no manipulation required)
C# Syntax (Toggle Plain Text)
string fileName = ""; string name; string[] array = new string[8999];//initialize array and size of (NOT USED) //int Count = 0;//set count to 0 to interate through file line by line for linear search OpenFileDialog OpenFile = new OpenFileDialog();//declare variable OpenFile.ShowDialog(); //show dialog box of files OpenFile.Filter = "Text files(*.txt)|*.txt|All files (*.*) | *.*"; //filter by these file types OpenFile.FilterIndex = 0;//show first file type? fileName = OpenFile.FileName;//declare variable if (OpenFile.ShowDialog() == DialogResult.OK)//if file found then display results to screen { foreach (string content in OpenFile.FileNames) { TextReader sr = new StreamReader(content);//read file using streamreader while ((name = sr.ReadLine()) != null)//read textreader variable line by line { listBox1.Items.Add(name); } sr.Close(); }
•
•
Join Date: Oct 2007
Posts: 10
Reputation:
Solved Threads: 0
does some-one know what I'm doing wrong here?
C# Syntax (Toggle Plain Text)
foreach (string content in OpenFile.FileNames)//sends opened file to variable. //{ TextReader sr = new StreamReader(content);//supposed to read file via StreamReader string contents = sr.ReadToEnd(); string[]myArray = (sr); foreach (string gotya in myArray ) { listBox1.Items.Add(gotya); }
•
•
Join Date: Oct 2007
Posts: 10
Reputation:
Solved Threads: 0
Yeah...Worked it out!, most of the stuff I discovered right here in DaniWeb...all that after scolling the net for the past...ages(I won't give actual time spent going around in circles trying to work it out prior to coming to DaniWeb, way too embrassing).
Well now on to part 2, 3 and documentation OOPs.
so, after all that here it is
Well now on to part 2, 3 and documentation OOPs.
so, after all that here it is
C# Syntax (Toggle Plain Text)
TextReader sr = new StreamReader(fileName); string contents = sr.ReadToEnd(); string[]myArray = {contents}; Array.Sort(myArray); foreach (string gotya in myArray) { txtBDisplayContents.Text = gotya; }
![]() |
Similar Threads
- C Program where gets(), getchar(), are not working. (C)
- HELP!!! (solving task) (C)
- Reading CSV in VC++ (C++)
- Need Help with ArrayList sorting (Java)
- reading a file into code (Java)
Other Threads in the C# Forum
- Previous Thread: 3D array access
- Next Thread: Real Newbie Help
| Thread Tools | Search this Thread |
.net access algorithm api array asp.net barchart bitmap box broadcast c# check checkbox client combobox control conversion csharp custom database databaseconnection datagrid datagridview dataset datetime dbconnection degrees design development draganddrop drawing encryption enum eventhandlers excel file firefox form format forms function gdi+ grantorrevokepermissionthroughc#.net image index input install java label libraries list listbox loop mandelbrot marshalbyrefobject math mouseclick movingimage mysql mysql.data.client operator path photoshop php picturebox pixelinversion platform post programming radians regex remoting resourcefile richtextbox server sleep socket sql statistics stream string study system.servicemodel table tcpclientchannel text textbox thread time timer update usercontrol validation visualstudio webbrowser windows winforms wpf wpfc# xml





