My objective is to read a text file and display the content in a table.
I have been through a lot of forum and goggling and still couldnt find a solution.
My Table format:
<table >
<`tr>
<`td>
Australia
<`/td>
<`td>
<`table>
<`tr>
<`td>
1
<`/td>
<`/tr>
<`/table>
<`/tr>
<`/table>
My TextFile look like:
Australia = 1,1,2,2
Malaysia = 1,1,1,2,2,2
Singapore = 1,1,1,1,2,2,2,2
My Reading code:
string path = @"..\TestFile.txt";
char token = ',';
char token2 = '=';
string[] lines = File.ReadAllLines(path);
Response.Write("<table>");
foreach (string line in lines)
{
string[] country = line.Split(token2);
string[] image = line.Split(token);
string row = "<tr><td>" + country + "</td>" +"<table><tr>";
Response.Write(row);
for (int i = 0; i < image.Length; i++)
{
string row2 = "<td>" + image[i] +"</td>";
Response.Write(row2);
}
Response.Write("</tr></table>");
}
Response.Write("</tr></table>");
my result:
System.String[]
Australia = 1 1 2 2
System.String[]
Malaysia = 1 1 1 2 2 2
System.String[]
Singapore = 1 1 1 1 2 2 2 2
and what i want to achieve :
Australia 1 1 2 2
Malaysia 1 1 1 2 2 2
Singapore 1 1 1 1 2 2 2 2
any help would be appreciated . Thanks!
If I understood problem correctly, try to do like this: