1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

distinguishing strings by line gaps

Discussion in 'Software Development' started by the_oliver, Feb 3, 2007.

Thread Status:
Not open for further replies.
Advertisement
  1. the_oliver

    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.
     
  2. lotuseclat79

    lotuseclat79

    Joined:
    Sep 12, 2003
    Messages:
    20,583
    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
     
  3. the_oliver

    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.
     
  4. Shadow2531

    Shadow2531

    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
    
     
  5. the_oliver

    the_oliver Thread Starter

    Joined:
    Jan 21, 2007
    Messages:
    5
    Right on the nail! Many Thanks
     
  6. Sponsor

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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/540784

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice