Link to home
Start Free TrialLog in
Avatar of rwheeler23
rwheeler23Flag for United States of America

asked on

VS 2008 C# Text File Export

I have this extraction program that creates a pipe delimited file. Right now it writes the records and preserves all spaces. I was wondering if there is a directive so will strip away all spaces or is there any other command to use when writing a text file that will do this?
foreach (DataRow dr_loopvariable in dt.Rows)
                {
                    dr = dr_loopvariable;
                    tw.WriteLine("{0,-10}{1,1}{2,-35}{3,1}{4,-35}{5,1}{6,-35}{7,1}{8,-35}{9,1}{10,-35}{11,1}{12,-35}{13,1}{14,-19}{15,1}{16,-2}{17,1}{18,-10}{19,1}{20,-10}{21,1}{22,-17}{23,1}{24,-13}{25,1}{26,-10}{27,1}{28,-4}{29,1}{30,-2}{31,1}{32,-30}{33,1}{34,-10}{35,1}{36,-13}", dr["VENDOR_ID"], P, dr["VENDOR_NAME"],P,dr["REMIT1"],P,dr["REMIT2"],P,dr["REMIT3"],P,dr["REMIT4"],P,dr["REMIT5"],P,dr["CITY"],P,dr["STATE"],P,dr["ZIP"],P,dr["CHECK_TOTAL"],P,dr["INVOICE_NUM"],P,dr["INV_NET_AMT"],P,dr["INV_DATE"],P,dr["DIVISION_ID"],P,dr["COUNTRY"],P,dr["DESCRIPTION"],P,dr["DISC_AMT"],P,dr["GROSS_INV_AMT"]);
                }

Open in new window

sample.txt
SOLUTION
Avatar of Member_2_4913559
Member_2_4913559
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rwheeler23

ASKER

Interesting. I will see what people think of the current format. Thanks for the tip.
Avatar of Norie
Norie

Just curious, but how are the spaces being added to the data?

Or does the data come with spaces?
The database is a MS database and all fields are defined as char not varchar.
So there fixed length.

I was just wondering if something like Trim could be used to get rid of any unwanted spaces, but I'm probably way off.:)
I suppose I could add the trim function to every field in the query but I like your idea better.
Both answers helped.