reading a file

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • microsoft.news.com

    reading a file

    I'm reading a text file data and creating a new one with only certain data.
    In the new file I need to format like so

    Delaware Dover
    Wilmington
    New Castle

    New York New York City
    Fishkill
    Watertown


    how can i format my new file such as this?

    the old file looks like this
    State City
    Delaware Dover
    Delaware Wilimington
    Delaware New Castle
    New York New York City
    New York Fishkill
    New York Watertown





  • Jon Skeet [C# MVP]

    #2
    Re: reading a file

    <"microsoft.new s.com" <CSharpCoder> > wrote:[color=blue]
    > I'm reading a text file data and creating a new one with only certain data.
    > In the new file I need to format like so
    >
    > Delaware Dover
    > Wilmington
    > New Castle
    >
    > New York New York City
    > Fishkill
    > Watertown
    >
    >
    > how can i format my new file such as this?
    >
    > the old file looks like this
    > State City
    > Delaware Dover
    > Delaware Wilimington
    > Delaware New Castle
    > New York New York City
    > New York Fishkill
    > New York Watertown[/color]

    Well, how far have you got so far? Do you have a detailed question?

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    • microsoft.news.com

      #3
      Re: reading a file

      How can i format my new file like this?
      I can get the data and see it, but I can have it appear like below?
      I never done this before so i'm stuck. I can read the current file, get the
      data out, but I need to group the states as below



      "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
      news:MPG.1d000f aea0b0953c98c1d b@msnews.micros oft.com...[color=blue]
      > <"microsoft.new s.com" <CSharpCoder> > wrote:[color=green]
      >> I'm reading a text file data and creating a new one with only certain
      >> data.
      >> In the new file I need to format like so
      >>
      >> Delaware Dover
      >> Wilmington
      >> New Castle
      >>
      >> New York New York City
      >> Fishkill
      >> Watertown
      >>
      >>
      >> how can i format my new file such as this?
      >>
      >> the old file looks like this
      >> State City
      >> Delaware Dover
      >> Delaware Wilimington
      >> Delaware New Castle
      >> New York New York City
      >> New York Fishkill
      >> New York Watertown[/color]
      >
      > Well, how far have you got so far? Do you have a detailed question?
      >
      > --
      > Jon Skeet - <skeet@pobox.co m>
      > http://www.pobox.com/~skeet
      > If replying to the group, please do not mail me too[/color]


      Comment

      • Jon Skeet [C# MVP]

        #4
        Re: reading a file

        <"microsoft.new s.com" <CSharpCoder> > wrote:[color=blue]
        > How can i format my new file like this?
        > I can get the data and see it, but I can have it appear like below?
        > I never done this before so i'm stuck. I can read the current file, get the
        > data out, but I need to group the states as below[/color]

        Well, you could use a Hashtable, and populate it with a ArrayLists -
        one per state, with each list containing cities. The key of the
        Hashtable would be the state, so you could quickly find the list of
        cities and add to it. Or you could create your own State class
        containing a list of cities.

        --
        Jon Skeet - <skeet@pobox.co m>
        Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

        If replying to the group, please do not mail me too

        Comment

        • microsoft.news.com

          #5
          Re: reading a file

          I don't know how to do that. Where can i find something like that online? I
          never used a hashtable or done anything like this before.
          "Jon Skeet [C# MVP]" <skeet@pobox.co m> wrote in message
          news:MPG.1d0014 129296a43c98c1d d@msnews.micros oft.com...[color=blue]
          > <"microsoft.new s.com" <CSharpCoder> > wrote:[color=green]
          >> How can i format my new file like this?
          >> I can get the data and see it, but I can have it appear like below?
          >> I never done this before so i'm stuck. I can read the current file, get
          >> the
          >> data out, but I need to group the states as below[/color]
          >
          > Well, you could use a Hashtable, and populate it with a ArrayLists -
          > one per state, with each list containing cities. The key of the
          > Hashtable would be the state, so you could quickly find the list of
          > cities and add to it. Or you could create your own State class
          > containing a list of cities.
          >
          > --
          > Jon Skeet - <skeet@pobox.co m>
          > http://www.pobox.com/~skeet
          > If replying to the group, please do not mail me too[/color]


          Comment

          • Jon Skeet [C# MVP]

            #6
            Re: reading a file

            <"microsoft.new s.com" <CSharpCoder> > wrote:[color=blue]
            > I don't know how to do that. Where can i find something like that online? I
            > never used a hashtable or done anything like this before.[/color]

            I suggest you read a tutorial on C# and .NET in general - learning it
            piecemeal isn't a particularly good idea. I don't have any particular
            recommendations in terms of books and tutorials, but there are plenty
            around.

            --
            Jon Skeet - <skeet@pobox.co m>
            Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

            If replying to the group, please do not mail me too

            Comment

            Working...