fixed width text file

Discussion in 'ASP .Net' started by John, Jun 13, 2006.

  1. John

    John Guest

    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.
    John, Jun 13, 2006
    #1
    1. Advertising

  2. 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" <> wrote in message
    news:%...
    >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.
    >
    John Timney \(MVP\), Jun 13, 2006
    #2
    1. Advertising

  3. John

    Tom Guest

    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)" <> wrote in message
    news:...
    > 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" <> wrote in message
    > news:%...
    >>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.
    >>

    >
    >
    Tom, Jun 13, 2006
    #3
  4. 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" <> wrote in message
    news:...
    > 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)" <> wrote in message
    > news:...
    >> 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" <> wrote in message
    >> news:%...
    >>>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.
    >>>

    >>
    >>

    >
    >
    John Timney \(MVP\), Jun 13, 2006
    #4
  5. John

    Guest

    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" <> wrote in message
    > news:...
    > > 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)" <> wrote in message
    > > news:...
    > >> 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" <> wrote in message
    > >> news:%...
    > >>>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, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    11
    Views:
    1,078
    Toby Inkster
    Jan 28, 2005
  2. johnp
    Replies:
    4
    Views:
    3,655
    Toby Inkster
    May 23, 2005
  3. ssk
    Replies:
    5
    Views:
    5,463
    Jukka K. Korpela
    Oct 30, 2006
  4. cera
    Replies:
    1
    Views:
    1,247
    Neredbojias
    Aug 18, 2007
  5. Replies:
    1
    Views:
    726
    Beauregard T. Shagnasty
    Dec 29, 2007
Loading...

Share This Page