Windows Vista Forums

Adding data to a hash table
  1. #1


    NeilOz Guest

    Adding data to a hash table

    I have imported a csv using import-csv

    $clcode = import-csv $csvlocation | select clcode



    $clcode results are a list of 6 digit numbers, for the next part of the
    script I need to add ',' to the end of the 6 digits, I have messed around
    with different methods and have been unable to figure out how to do it,
    easily.

    Please help
    Neil

      My System SpecsSystem Spec

  2. #2


    Jeff Guest

    Re: Adding data to a hash table

    On Dec 28, 8:13 am, NeilOz <Nei...@xxxxxx> wrote:

    > I have imported a csv using import-csv
    >
    > $clcode = import-csv $csvlocation | select clcode
    >
    > $clcode results are a list of 6 digit numbers, for the next part of the
    > script I need to add ',' to the end of the 6 digits, I have messed around
    > with different methods and have been unable to figure out how to do it,
    > easily.
    >
    > Please help
    > Neil
    Neil,

    This should do the trick:

    for ( $i = 0; $i -lt $clcode.Length; $i++ )
    {
    $clcode[ $i ] += ","
    }

    Jeff

      My System SpecsSystem Spec

  3. #3


    Karl Prosser[MVP] Guest

    Re: Adding data to a hash table

    import-csv creates a collection of objects with properties generated
    from your columns in the csv.

    so here i presume clcode is the name of that column.. then you could do
    something like this

    import-csv $csvlocation | foreach { $_.clcode += ',' }


    NeilOz wrote:

    > I have imported a csv using import-csv
    >
    > $clcode = import-csv $csvlocation | select clcode
    >
    > $clcode results are a list of 6 digit numbers, for the next part of the
    > script I need to add ',' to the end of the 6 digits, I have messed around
    > with different methods and have been unable to figure out how to do it,
    > easily.
    >
    > Please help
    > Neil

      My System SpecsSystem Spec

  4. #4


    Keith Hill [MVP] Guest

    Re: Adding data to a hash table

    "NeilOz" <NeilOz@xxxxxx> wrote in message
    news:64A62FA8-4C54-49AC-9EEC-993ABB38D334@xxxxxx

    > I have imported a csv using import-csv
    >
    > $clcode = import-csv $csvlocation | select clcode
    >
    > $clcode results are a list of 6 digit numbers, for the next part of the
    > script I need to add ',' to the end of the 6 digits, I have messed around
    > with different methods and have been unable to figure out how to do it,
    > easily.
    Try this:

    $clcode = import-csv $csvlocation | select clcode | foreach
    {"$($_.clcode),"}

    This just uses string interpolation to convert the number into a string
    followed by the comma.

    --
    Keith


      My System SpecsSystem Spec

Adding data to a hash table problems?

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting a Hash Table before outputting it to html TimParker PowerShell 3 03 Jan 2009
How to create a hash table from an array RickB PowerShell 2 08 Aug 2008
Passing hash table by reference Orimslala PowerShell 2 12 Sep 2007
Variable as hash table issue Romu PowerShell 2 22 Jan 2007
How do I read a XML file into a hash table? wangxiaohu PowerShell 3 18 Oct 2006