Windows Vista Forums

read strings to variable

  1. #1


    James Guest

    read strings to variable

    I have a text file like this:


    1234 45566, 78923 10/02, 10/03, 10/04
    6543 46765, 35643 23/03

    I want the script to look at each line and read the first string to a
    variable(e.g. 1234), then read all strings after and including the
    fourth string to another variable (eg. 10/02 to variable, 10/03 to
    another variable etc) and then write those variables to a line in
    another text file. It would do this for each line in the text file. The
    fourth string and after dates and I would like to write it as 2009/10/02
    for example.

    Basically I want to grab specific text from each line of the text file
    and add them to commands. Can anyone help?

    Thanks,

    James

      My System SpecsSystem Spec

  2.   


  3. #2


    Pegasus [MVP] Guest

    Re: read strings to variable


    "James" <jwanders@xxxxxx> wrote in message
    news:Tznom.137737$cf6.136849@xxxxxx

    >I have a text file like this:
    >
    >
    > 1234 45566, 78923 10/02, 10/03, 10/04
    > 6543 46765, 35643 23/03
    >
    > I want the script to look at each line and read the first string to a
    > variable(e.g. 1234), then read all strings after and including the fourth
    > string to another variable (eg. 10/02 to variable, 10/03 to another
    > variable etc) and then write those variables to a line in another text
    > file. It would do this for each line in the text file. The fourth string
    > and after dates and I would like to write it as 2009/10/02 for example.
    >
    > Basically I want to grab specific text from each line of the text file and
    > add them to commands. Can anyone help?
    >
    > Thanks,
    >
    > James
    You need to read each line with the ReadLine method of the File System
    Object. You then split each line into its components like so:

    aComponents = split(sLine)

    This will allow you to access each component separately:

    wscript.echo "String 1 = " & aComponents(0)
    wscript.echo "String 2 = " & aComponents(1)
    etc.

    All of the above is covered extensively, with examples, in the help file
    script56.chm which you can download from the Microsoft site.



      My System SpecsSystem Spec


read strings to variable
Similar Threads
Thread Forum
Has anyone sucessfully read the value of the $OFS variable? PowerShell
Read-Host issue, won't store to variable when using multiple read-host lines PowerShell
Read strings from resource DLL, WinFX , C# WinFX General
Read strings from satellite DLL, Winfx C# Avalon
Variable expansion in strings PowerShell