• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

read strings to variable

J

James

#1
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 Computer

P

Pegasus [MVP]

#2
"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 Computer

Users Who Are Viewing This Thread (Users: 1, Guests: 0)