468,110 Members | 1,846 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,110 developers. It's quick & easy.

fixed width text file

I can create text file, but how can I create a text file where the values
are at the same location on every line?

I want to define the location where the values starts and define the length
of the value.
Jun 12 '06 #1
4 1917
If you assume every line was 80 chars in length and append a carriage return
at the end of every line you have something to measure and pad spaces
against. This will give you fixed positioning within the file, but you'll
need to force font to something like courier to see this aligned when you
view it which I dont think you can do in the text file itself. For that
you'll need to use RTF, PDF or something else for that.
--
Regards

John Timney (MVP)

"John" <me@me.com> wrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
I can create text file, but how can I create a text file where the values
are at the same location on every line?

I want to define the location where the values starts and define the
length of the value.

Jun 13 '06 #2
Tom
each line can be different in length. I get text files now that are fixed
how are they created?
example:
line 1
20060601 BMW 1999 Smith 45,500
20050601 BMW 2003 Jones 75,200
20060102 Lexus 2006 Smith 25,365

and I have to read this files and get all the data, so now I need to create
a file in this format so I can send out and have a vendor read it.

there has to b a way in doing this

"John Timney (MVP)" <x_****@timney.eclipse.co.uk> wrote in message
news:Q6********************@eclipse.net.uk...
If you assume every line was 80 chars in length and append a carriage
return at the end of every line you have something to measure and pad
spaces against. This will give you fixed positioning within the file, but
you'll need to force font to something like courier to see this aligned
when you view it which I dont think you can do in the text file itself.
For that you'll need to use RTF, PDF or something else for that.
--
Regards

John Timney (MVP)

"John" <me@me.com> wrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
I can create text file, but how can I create a text file where the values
are at the same location on every line?

I want to define the location where the values starts and define the
length of the value.


Jun 13 '06 #3
Thats just looks to be tab delimited data. Try adding vbTab or \t if its
c# to your text string and see if thats what your after.

outputString = "This is text" & vbTab & "and text after tab"

outputString = "This is text text\tand text after tab";

--
Regards

John Timney (MVP)
"Tom" <To*@gmail.com> wrote in message
news:ep**************@TK2MSFTNGP04.phx.gbl...
each line can be different in length. I get text files now that are fixed
how are they created?
example:
line 1
20060601 BMW 1999 Smith 45,500
20050601 BMW 2003 Jones 75,200
20060102 Lexus 2006 Smith 25,365

and I have to read this files and get all the data, so now I need to
create a file in this format so I can send out and have a vendor read it.

there has to b a way in doing this

"John Timney (MVP)" <x_****@timney.eclipse.co.uk> wrote in message
news:Q6********************@eclipse.net.uk...
If you assume every line was 80 chars in length and append a carriage
return at the end of every line you have something to measure and pad
spaces against. This will give you fixed positioning within the file,
but you'll need to force font to something like courier to see this
aligned when you view it which I dont think you can do in the text file
itself. For that you'll need to use RTF, PDF or something else for that.
--
Regards

John Timney (MVP)

"John" <me@me.com> wrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
I can create text file, but how can I create a text file where the values
are at the same location on every line?

I want to define the location where the values starts and define the
length of the value.



Jun 13 '06 #4
here's a better way =)

// 12345 12345
// will output "abc | def"
Console.WriteLine("{0,-5}|{1,5}", "abc", "def");
// this will also produce the same results, but stored in
// a string so you can output it to a text filee
string str = string.Format("{0,-5}|{1,5}", "abc", "def");

Console.ReadLine();

in the format string "{0,-5}", the -5 says "pad to a width of 5 spaces,
and put the data on the left"
the "{0,5}" says "pad to a width of 5 spaces, and put the data on the
right"

this isn't going to work if you have data that is 6 or more characters
long, it'll just write the whole word out, but you could always to a
"longdata".Substring(0, 5) to grab the first 5 characters

sound good?

John Timney (MVP) wrote:
Thats just looks to be tab delimited data. Try adding vbTab or \t if its
c# to your text string and see if thats what your after.

outputString = "This is text" & vbTab & "and text after tab"

outputString = "This is text text\tand text after tab";

--
Regards

John Timney (MVP)
"Tom" <To*@gmail.com> wrote in message
news:ep**************@TK2MSFTNGP04.phx.gbl...
each line can be different in length. I get text files now that are fixed
how are they created?
example:
line 1
20060601 BMW 1999 Smith 45,500
20050601 BMW 2003 Jones 75,200
20060102 Lexus 2006 Smith 25,365

and I have to read this files and get all the data, so now I need to
create a file in this format so I can send out and have a vendor read it.

there has to b a way in doing this

"John Timney (MVP)" <x_****@timney.eclipse.co.uk> wrote in message
news:Q6********************@eclipse.net.uk...
If you assume every line was 80 chars in length and append a carriage
return at the end of every line you have something to measure and pad
spaces against. This will give you fixed positioning within the file,
but you'll need to force font to something like courier to see this
aligned when you view it which I dont think you can do in the text file
itself. For that you'll need to use RTF, PDF or something else for that.
--
Regards

John Timney (MVP)

"John" <me@me.com> wrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
I can create text file, but how can I create a text file where the values
are at the same location on every line?

I want to define the location where the values starts and define the
length of the value.



Jun 14 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Jaz | last post: by
179 posts views Thread by SoloCDM | last post: by
4 posts views Thread by Charles Russell | last post: by
5 posts views Thread by Johnny Meredith | last post: by
2 posts views Thread by Brian Henry | last post: by
4 posts views Thread by Jeff | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.