From: Bill on
Hello

I'm looping over a file ,and as I get each line I'm looking for a particualr
name. I've tried use the split method, but each line contains whitespaces,
and an un even number of white spaces, so the text item I'm looking for
isn't always th esame element.

Here is a sample of each line of text I I get

devicetype1 address1 sn1 file1.txt cost1
devicetype2 address2 sn2 file2.txt cost2

The file I'm looking for has the .txt extension it, so how would I go about
finding the location, and going backwards till the firs twhite space??

Thanks


From: Pegasus [MVP] on


"Bill" <someplace(a)somewhere.com> wrote in message
news:u43FsDi7KHA.5412(a)TK2MSFTNGP06.phx.gbl...
> Hello
>
> I'm looping over a file ,and as I get each line I'm looking for a
> particualr name. I've tried use the split method, but each line contains
> whitespaces, and an un even number of white spaces, so the text item I'm
> looking for isn't always th esame element.
>
> Here is a sample of each line of text I I get
>
> devicetype1 address1 sn1 file1.txt cost1
> devicetype2 address2 sn2 file2.txt cost2
>
> The file I'm looking for has the .txt extension it, so how would I go
> about finding the location, and going backwards till the firs twhite
> space??
>
> Thanks

To find the .txt string, use the InStr method. This allows you to turn the
string
devicetype1 address1 sn1 file1.txt cost1
into this one:
devicetype1 address1 sn1 file1.txt
You now use the InStrRev method to find the right-most space. Both methods
are described in detail in the downloadable file script56.chm, with actual
examples.

From: Steve on
Bill wrote:
>
> I'm looping over a file ,and as I get each line I'm looking for a
> particualr name. I've tried use the split method, but each line
> contains whitespaces, and an un even number of white spaces, so the
> text item I'm looking for isn't always th esame element.
>
> Here is a sample of each line of text I I get
>
> devicetype1 address1 sn1 file1.txt cost1
> devicetype2 address2 sn2 file2.txt cost2
>
> The file I'm looking for has the .txt extension it, so how would I go
> about finding the location, and going backwards till the firs twhite
> space??

I use regular expressions to parse free-form strings:

===

' use array to mimic file input
input = Array( _
"devicetype1 address1 sn1 file1.txt cost1", _
"devicetype2 address2 sn2 file2.txt cost2" _
)

Set parser = New RegExp
parser.Pattern = "\S+\.txt\b"
parser.IgnoreCase = True

For Each line In input
For Each match In parser.Execute(line) ' there will only be 1 match
' process file name here
WScript.Echo match
Next
Next

===

--
Steve

America is the only country that went from barbarism to decadence
without civilization in between. -Oscar Wilde