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. #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
Re: Variable not getting replace when read through XML
Will you only have one variable to replace or could it be more than one? Marco "@lways" <lways@newsgroup> wrote in message...
PowerShell
Re: How to display a variable value in a dialog box and how to read user input?
Tony wrote: You can use the MsgBox function to display anything. You can concatenate the value of a variable into a string to display. For...
VB Script
Has anyone sucessfully read the value of the $OFS variable?
All the code I search in books and online will do something like this $OFS = <some character> but none of them first save the orignal value ...
PowerShell
Read-Host issue, won't store to variable when using multiple read-host lines
I am prompting the user to enter new user information in using Read- Host. The only problem is, when I run my function and enter the data in, it...
PowerShell
Read strings from resource DLL, WinFX , C#
Hi All: I have a resource WinFX satellite DLL generated by specifying culture in VCPROJ. (The en-US DLL is then used by LOCBAML tool for...
WinFX General
Read strings from satellite DLL, Winfx C#
Hi All: I have a resource WinFX satellite DLL generated by specifying culture in VCPROJ. (The en-US DLL is then used by LOCBAML tool for...
Avalon
Variable expansion in strings
I know you can do this: > $x = "Hello" > "${x} World!" Hello World! But what is the right way to do this with items in arrays? > $x =...
PowerShell