Click here to Skip to main content
15,912,400 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi Sir,
Good day to all!, can I ask sample code in C# on how to read and get the fixed space delimited text file (as a sample below is the format of text file) and and store it on the array loop or temp file? so that I could manipulate every field. Thanks in advance sir.

MSIL
tag ord_no  ref_no  prog_no    prog_date           acv_type_id
--- ------- ------- ---------- ------------------- -----------
DL 6636500    1       11       Feb 3 2011 11:11AM  DLINSTLN
DL 6649978    1        8       Feb 4 2011 12:29PM  DLINSTLN
DL 6722809    1        3       Feb 2 2011  5:35PM  DLINSTLN
Posted

i think this link will help you
Split Method
 
Share this answer
 
Comments
Silver Lightning 14-Feb-11 20:42pm    
Ooopps sorry sir, yes your link is correct, do you think it is possible that I could convert all the parsed string from array to excel file? do you have any sample code? thanks sir
corsairsoft 14-Feb-11 20:53pm    
for example you can use like this.. i parse every words in your file lines
you can set them to variables and do everything.. enjoy

private void button1_Click(object sender, EventArgs e)
{
string line;
System.IO.StreamReader file = new System.IO.StreamReader("sample.txt");
while ((line = file.ReadLine()) != null)
{
char[] delimiterChars = { ' ', ',', '.', ':', '\t' };
string[] words = line.Split(delimiterChars);

foreach (string s in words)
{
MessageBox.Show(s);
}

}
file.Close();
}
corsairsoft 14-Feb-11 20:58pm    
btw. excel can import that file directly just set a delimiter char while import
Silver Lightning 15-Feb-11 1:06am    
thanks sir, but I need to transfer all data in text file to excel file (include headers and by columns). Any idea or code that I on how could I expand your given code sir? Your help really much appreciated. Thank you sir corsairsoft.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900