| | |
cast text file to an array
Please support our C# advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
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 animation array bitmap box c# check checkbox client combobox control conversion csharp customactiondata database datagrid datagridview dataset datastructure date/time datetime datetimepicker degrees directrobot dll draganddrop drawing encryption enum excel file filename files form format formbox forms function gdi+ gis gtk hash image input install java label list mandelbrot math mouseclick mp3 mysql native operator outlook2003 packaging path photoshop picturebox pixelinversion pixelminversion post print process programming radians regex remoting richtextbox safari server sleep snooze socket sql statistics string table tables tcp text textbox thread time timer update usercontrol usercontrols validation visualstudio webbrowser webcam wfa wia winforms wpf xml





