distinguishing strings by line gaps

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

the_oliver

Thread Starter
Joined
Jan 21, 2007
Messages
5
Hello,

I have a .vbs scrip which takes each line in a txt file as a variable, one line at a time. What i need is to be able to but two variables on a line. And for the script to read through the file, still one line at a time. E.g:

Variable1 Variable2
Variable1 Variable2

For example Variable1 could be where a file is, and Variable2 where its coppying two?

Thanks for any help you can offer.
 
Joined
Sep 12, 2003
Messages
20,583
the_oliver said:
Hello,

I have a .vbs scrip which takes each line in a txt file as a variable, one line at a time. What i need is to be able to but two variables on a line. And for the script to read through the file, still one line at a time. E.g:

Variable1 Variable2
Variable1 Variable2

For example Variable1 could be where a file is, and Variable2 where its coppying two?

Thanks for any help you can offer.
Hi Oliver,

In hexadecimal notation, a newline character is: 0A which is contained in a byte of 8 bits where in binary it is: 00001010, i.e. 0000 = 0, 0001 = 1, 0010 = 2, 0011 = 3, 0100 = 4, 0101 = 5, 0110 = 6, 0111 = 7, 1000 = 8, 1001 = 9, 1010 = A, 1011 = B, 1100 = C, 1101 = D, 1110 = E, 1111 = F, ...

Also, in hexadecimal notation, a Space character is: 20 or in binary 00100000

If you can scan a line character by character and put each character into an array of characters until a newline character is reached, then your array of characters contains a full line, which you already have in your variable.

If you then scan the array for a Space character, then you can distinguish between the file in the first variable and the folder/directory where it will be copied to in the second variable. Of course, the first non-space character after the first space after the first variable would find the start of the second variable.

-- Tom
 

the_oliver

Thread Starter
Joined
Jan 21, 2007
Messages
5
Many thanks, but i think doing this slightly suparses my knowlage of .vbs. Could you give me a point in the right direction?

Thanks.
 
Joined
Apr 30, 2001
Messages
2,636
I don't know .vbs at all, but looking on google, you'd do it something like the following (with some extra error handling)

test.vbs
Code:
Dim infile, fileptr, vars, v1, v2
Set fileptr = CreateObject("Scripting.fileSystemObject")
Set infile = fileptr.OpenTextFile("test.txt", 1)
Do while Not infile.AtEndOfStream
    vars = Split(infile.readline, " ")
    v1 = vars(0)
    v2 = vars(1)
    WScript.Echo v1
    WScript.Echo v2
Loop
infile.Close
Set fileptr = Nothing
WSCRIPT.QUIT(0)
test.txt
Code:
Variable1 Variable2
Variable3 Variable4
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

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

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top