Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - read strings to variable

Reply
 
Old 09-05-2009   #1 (permalink)
James


 
 

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
Old 09-05-2009   #2 (permalink)
Pegasus [MVP]


 
 

Re: read strings to variable


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

>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
Reply

Thread Tools


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
Variable expansion in strings PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46