EDN Admin
Well-known member
I have a text file that is unstructured, so no clear delimiters other than n for end of line. The length of lines varies and the length of the file varies.
I have written code that opens the file and puts it into a character array using ToCharArray().
What I am trying to do now is to programatically create a table where each cell has one character in it (including white space characters). Once in the table I can then manipulate each cell as needed and eventually export to a structured file, maybe CSV
or XML.
My problem is that whilst I am familiar with C (from 20 years ago) I am unfamiliar with OO but I want to use C# within Visual Studio 2010 as this will eventually be part of a Windows form program.
All the examples I have found deal with splitting strings into delimited fields (CSV or white space).
I just cant see how to make a table of unknown size, to place a character into a cell and to create new rows in the table.
<pre class="prettyprint public void parseCSV(string path)
{
char[] FileAsCharArray;
int FileLength, i = 0;
int RowIndex = 1;
// define a string called FileContent and populate with the entire contents of path
string FileContent = File.ReadAllText(path);
FileLength = FileContent.Length;
// Display raw test tile in lower window textBox1
textBox1.Text = FileContent;
//Create an array of characters called FileAsCharArray from the raw test file
FileAsCharArray = FileContent.ToCharArray();
}[/code]
If I use some output mechanism like MessageBox.Show I can verify the characters are in the array.
Any help will be gratefully received.<br/>
View the full article
I have written code that opens the file and puts it into a character array using ToCharArray().
What I am trying to do now is to programatically create a table where each cell has one character in it (including white space characters). Once in the table I can then manipulate each cell as needed and eventually export to a structured file, maybe CSV
or XML.
My problem is that whilst I am familiar with C (from 20 years ago) I am unfamiliar with OO but I want to use C# within Visual Studio 2010 as this will eventually be part of a Windows form program.
All the examples I have found deal with splitting strings into delimited fields (CSV or white space).
I just cant see how to make a table of unknown size, to place a character into a cell and to create new rows in the table.
<pre class="prettyprint public void parseCSV(string path)
{
char[] FileAsCharArray;
int FileLength, i = 0;
int RowIndex = 1;
// define a string called FileContent and populate with the entire contents of path
string FileContent = File.ReadAllText(path);
FileLength = FileContent.Length;
// Display raw test tile in lower window textBox1
textBox1.Text = FileContent;
//Create an array of characters called FileAsCharArray from the raw test file
FileAsCharArray = FileContent.ToCharArray();
}[/code]
If I use some output mechanism like MessageBox.Show I can verify the characters are in the array.
Any help will be gratefully received.<br/>
View the full article