Home     |     .Net Programming    |     cSharp Home    |     Sql Server Home    |     Javascript / Client Side Development     |     Ajax Programming

Ruby on Rails Development     |     Perl Programming     |     C Programming Language     |     C++ Programming     |     IT Jobs

Python Programming Language     |     Laptop Suggestions?    |     TCL Scripting     |     Fortran Programming     |     Scheme Programming Language


 
 
Cervo Technologies
The Right Source to Outsource

MS Dynamics CRM 3.0

Asp.Net Programming

Parsing a text file


Whats the best way for me to pull out records from a tab delimited text
file?

Or rather HOW do I parse the text, knowing that the tabs are field
delimiters and a return (I image) signifies a new record
?
JJ

On Jun 6, 4:31 pm, "JJ" <a@xyz.com> wrote:

> Whats the best way for me to pull out records from a tab delimited text
> file?

> Or rather HOW do I parse the text, knowing that the tabs are field
> delimiters and a return (I image) signifies a new record
> ?
> JJ

something like this

DataTable dt = new DataTable();

dt.Columns.Add(new DataColumn("column1"));
dt.Columns.Add(new DataColumn("column2"));

string[] lines = TextBox1.Text.Trim().Split('\r');
string[] s = null;

foreach (string line in lines)
{
DataRow row = dt.NewRow();

string[] fields = line.Split('\t');

s[0] = fields[0];
s[1] = fields[1];

row.ItemArray = s;
dt.Rows.Add(row);

}

GridView1.DataSource = dt;
GridView1.DataBind();

-----------------------------------------------Reply-----------------------------------------------
On Jun 6, 4:40 pm, Alexey Smirnov <alexey.smir@gmail.com> wrote:

> string[] fields = line.Split('\t');

> s[0] = fields[0];
> s[1] = fields[1];

> row.ItemArray = s;
> dt.Rows.Add(row);

Well... this should be optimized:

string[] fields = line.Split('\t');
row.ItemArray = fields;
dt.Rows.Add(row);

-----------------------------------------------Reply-----------------------------------------------

Great - thanks.
JJ
"Alexey Smirnov" <alexey.smir@gmail.com> wrote in message

news:1181140859.736333.94020@q66g2000hsg.googlegroups.com...

Actually, another question:
Could I open the text file from a path to the users file on their computer,
or do I have to (or is it best to) upload the text file first?
JJ
"Alexey Smirnov" <alexey.smir@gmail.com> wrote in message

news:1181141081.950087.56430@g4g2000hsf.googlegroups.com...

On Jun 6, 4:49 pm, "JJ" <a@xyz.com> wrote:

> or do I have to (or is it best to) upload the text file first?

Yes, user should upload the file.

Another way is to use a TextBox Control where user could copy/paste an
entire content of the file

-----------------------------------------------Reply-----------------------------------------------

I'd prefer it if they could paste as I'd not have to worry about storage
space, but the files in question will have around 3000 lines, so I'm not
sure if that is going to be possible/practical...?
JJ
"Alexey Smirnov" <alexey.smir@gmail.com> wrote in message

news:1181150841.937790.142050@i38g2000prf.googlegroups.com...

On Jun 6, 8:31 pm, "JJ" <a@xyz.com> wrote:

> possible

yes

> practical...?

don't know :-) but it can be a good option, I think.

-----------------------------------------------Reply-----------------------------------------------
I guess to avoid my worry of too many files being uploaded, I could just get
them to choose the file on their computer, then read the file and store it
in a static filename (so it keeps over-writing the old one); as I won't need
the file after I've parsed it (and input the fields into a database), that
should be ok.

Hang on though - that wouldn't work if someone else tried to do another
upload at exactly the same time.

I'm not sure their going to like copying and pasting such large files. I
agree though, I'd much rather copying and pasting myself - a lot simpler.
It looks like its either that or an ever growing number of files that I
haven't given them permission to delete.

JJ

"Alexey Smirnov" <alexey.smir@gmail.com> wrote in message

news:1181155473.991767.321600@i38g2000prf.googlegroups.com...

On Jun 6, 9:00 pm, "JJ" <a@xyz.com> wrote:

> I guess to avoid my worry of too many files being uploaded, I could just get
> them to choose the file on their computer, then read the file and store it
> in a static filename (so it keeps over-writing the old one); as I won't need
> the file after I've parsed it (and input the fields into a database), that
> should be ok.

> Hang on though - that wouldn't work if someone else tried to do another
> upload at exactly the same time.

> I'm not sure their going to like copying and pasting such large files. I
> agree though, I'd much rather copying and pasting myself - a lot simpler.
> It looks like its either that or an ever growing number of files that I
> haven't given them permission to delete.

A copy/paste approach is good when you have an Excel file and you can
open it, modify and copy the entire contents directly from Excel to
the web site (with a TextBox) without saving the file as a tab-
delimeted (or CSV) export and doing an upload.

But if you already have such file the way with upload is fast and
secure...

-----------------------------------------------Reply-----------------------------------------------

Yes - it will be an excel file they'll have. I guess 3000 lines is possible
to cut and paste....
I'm not sure what the limitations are in terms of memory within excels
clipboard.

I would have though 3000 lines was well within limits, would you?
JJ

"Alexey Smirnov" <alexey.smir@gmail.com> wrote in message

news:1181157942.355841.47430@g37g2000prf.googlegroups.com...

On Jun 6, 9:33 pm, "JJ" <a@xyz.com> wrote:

> Yes - it will be an excel file they'll have. I guess 3000 lines is possible
> to cut and paste....
> I'm not sure what the limitations are in terms of memory within excels
> clipboard.

> I would have though 3000 lines was well within limits, would you?
> JJ

The Office clipboard is limited, but the Windows clipboard depends on
the RAM only.

I think, you should test if users will not have any problems with copy
and paste. I think 3000-lines-file is big, but not because of its size
in bytes but because you cannot be sure that you have pasted the whole
file in the small textbox area on the form. Though you can show the
number of submitted lines using a client js, and/ or on a postback

-----------------------------------------------Reply-----------------------------------------------

What method should I use to sort/edit/delete the data, in case the user
wants to adjust the data before inputting it to the database?

JJ

"Alexey Smirnov" <alexey.smir@gmail.com> wrote in message

news:1181161054.175320.150750@o11g2000prd.googlegroups.com...

What I mean is how would I temporarily hold the data whilst any
sorting/deleting/editing can take place?

"JJ" <a@xyz.com> wrote in message

news:%236D4HgKqHHA.4212@TK2MSFTNGP04.phx.gbl...

Add to del.icio.us | Digg this | Stumble it | Powered by Megasolutions Inc