Hello,

I have a script where I read an input file, which contains a bunch of URL
strings of differing sizes. I split each element into an array based on the
slash ("/"). After that, I take one of the elements from the array, and
change it to another, and then put the URL string back together. The issue
I'm having is when I put it back together in a for each loop, it writes each
element onto its own line. Also, at the end of the line it puts a slash at
the end. How can I get each element to print on the same line, also omitting
the final slash? Here's the snippet of my code that does all this work...

Any help is greatly appreciated!
Sheel

example of line in input file: http://www.sheel.com/this/is/only/atest.pdf

Set myInputFile = fso.OpenTextFile("<input file>", ForReading)
Set MyOutputFile = fso.CreateTextFile("<output file>", True)

Dim arrIPAddress
Dim orgSplitter
Dim i

i = 0
Do Until myInputFile.AtEndOfStream
strLine = myInputFile.ReadLine
If inStr(strLine, "/") Then
arrIPAddress = split(strLine,"/")
arrIPAddress(2) = "www.soa.org"
For Each item in arrIPAddress
MyOutputFile.Writeline(item & "/")
i = i + 1
Next
End If
Loop

RE: For Each loop writing on same line by Sheel

Sheel
Tue Nov 27 12:20:01 PST 2007

Just an update, I have figured out the printing out of each URL into the same
line, but the trailing slash at the end of the output file is still a
problem. Also, to add a little bit of complexity, the possibility of a URL
string ending in a folder path does exist.

http://www.sheel.com/this/is/only/atest.pdf becomes
http://new.sheel.com/this/is/only/atest.pdf/ <-- don't want that last slash
after .pdf

Thanks again in advance!
Sheel

"Sheel" wrote:

> Hello,
>
> I have a script where I read an input file, which contains a bunch of URL
> strings of differing sizes. I split each element into an array based on the
> slash ("/"). After that, I take one of the elements from the array, and
> change it to another, and then put the URL string back together. The issue
> I'm having is when I put it back together in a for each loop, it writes each
> element onto its own line. Also, at the end of the line it puts a slash at
> the end. How can I get each element to print on the same line, also omitting
> the final slash? Here's the snippet of my code that does all this work...
>
> Any help is greatly appreciated!
> Sheel
>
> example of line in input file: http://www.sheel.com/this/is/only/atest.pdf
>
> Set myInputFile = fso.OpenTextFile("<input file>", ForReading)
> Set MyOutputFile = fso.CreateTextFile("<output file>", True)
>
> Dim arrIPAddress
> Dim orgSplitter
> Dim i
>
> i = 0
> Do Until myInputFile.AtEndOfStream
> strLine = myInputFile.ReadLine
> If inStr(strLine, "/") Then
> arrIPAddress = split(strLine,"/")
> arrIPAddress(2) = "www.soa.org"
> For Each item in arrIPAddress
> MyOutputFile.Writeline(item & "/")
> i = i + 1
> Next
> End If
> Loop

Re: For Each loop writing on same line by Tom

Tom
Tue Nov 27 12:59:05 PST 2007

On Nov 27, 3:20 pm, Sheel <Sh...@discussions.microsoft.com> wrote:
> Just an update, I have figured out the printing out of each URL into the same
> line, but the trailing slash at the end of the output file is still a
> problem. Also, to add a little bit of complexity, the possibility of a URL
> string ending in a folder path does exist.
>
> http://www.sheel.com/this/is/only/atest.pdfbecomeshttp://new.sheel.com/this/is/only/atest.pdf/ <-- don't want that last slash
> after .pdf
>
> Thanks again in advance!
> Sheel
>
> "Sheel" wrote:
> > Hello,
>
> > I have a script where I read an input file, which contains a bunch of URL
> > strings of differing sizes. I split each element into an array based on the
> > slash ("/"). After that, I take one of the elements from the array, and
> > change it to another, and then put the URL string back together. The issue
> > I'm having is when I put it back together in a for each loop, it writes each
> > element onto its own line. Also, at the end of the line it puts a slash at
> > the end. How can I get each element to print on the same line, also omitting
> > the final slash? Here's the snippet of my code that does all this work...
>
> > Any help is greatly appreciated!
> > Sheel
>
> > example of line in input file:http://www.sheel.com/this/is/only/atest.pdf
>
> > Set myInputFile = fso.OpenTextFile("<input file>", ForReading)
> > Set MyOutputFile = fso.CreateTextFile("<output file>", True)
>
> > Dim arrIPAddress
> > Dim orgSplitter
> > Dim i
>
> > i = 0
> > Do Until myInputFile.AtEndOfStream
> > strLine = myInputFile.ReadLine
> > If inStr(strLine, "/") Then
> > arrIPAddress = split(strLine,"/")
> > arrIPAddress(2) = "www.soa.org"
> > For Each item in arrIPAddress
> > MyOutputFile.Writeline(item & "/")
> > i = i + 1
> > Next
> > End If
> > Loop

Replace your loop with the Join function instead ...

i = 0
Do Until myInputFile.AtEndOfStream
strLine = myInputFile.ReadLine
If inStr(strLine, "/") Then
arrIPAddress = split(strLine,"/")
arrIPAddress(2) = "www.soa.org"
MyOutputFile.Writeline Join(arrIPAddress, "/")
i = i + 1
end if
Loop

Tom Lavedas
===========
http://members.cox.net/tglbatch/wsh/

Re: For Each loop writing on same line by Anthony

Anthony
Tue Nov 27 12:56:36 PST 2007


"Sheel" <Sheel@discussions.microsoft.com> wrote in message
news:AF03230D-828D-421F-A8E3-83784A0089A4@microsoft.com...
> Just an update, I have figured out the printing out of each URL into the
same
> line, but the trailing slash at the end of the output file is still a
> problem. Also, to add a little bit of complexity, the possibility of a URL
> string ending in a folder path does exist.
>
> http://www.sheel.com/this/is/only/atest.pdf becomes
> http://new.sheel.com/this/is/only/atest.pdf/ <-- don't want that last
slash
> after .pdf
>

What you need is the opposite of split that is Join. Use this instead of
your foreach loop:-

MyOutputFile.Writeline Join(arrIPAddress, "/")

Join will only place a / in between elements of the array as it concatenates
them together. It won't place one on the end. The only exception to this
would be if the input string had a final / on the end. In which case the
resulting array would have an empty element at the end.

BTW what does i do and why is the array called IPAddress.

--
Anthony Jones - MVP ASP/ASP.NET


PS RTM http://msdn2.microsoft.com/en-us/library/3ca8tfek.aspx

> Thanks again in advance!
> Sheel
>
> "Sheel" wrote:
>
> > Hello,
> >
> > I have a script where I read an input file, which contains a bunch of
URL
> > strings of differing sizes. I split each element into an array based on
the
> > slash ("/"). After that, I take one of the elements from the array, and
> > change it to another, and then put the URL string back together. The
issue
> > I'm having is when I put it back together in a for each loop, it writes
each
> > element onto its own line. Also, at the end of the line it puts a slash
at
> > the end. How can I get each element to print on the same line, also
omitting
> > the final slash? Here's the snippet of my code that does all this
work...
> >
> > Any help is greatly appreciated!
> > Sheel
> >
> > example of line in input file:
http://www.sheel.com/this/is/only/atest.pdf
> >
> > Set myInputFile = fso.OpenTextFile("<input file>", ForReading)
> > Set MyOutputFile = fso.CreateTextFile("<output file>", True)
> >
> > Dim arrIPAddress
> > Dim orgSplitter
> > Dim i
> >
> > i = 0
> > Do Until myInputFile.AtEndOfStream
> > strLine = myInputFile.ReadLine
> > If inStr(strLine, "/") Then
> > arrIPAddress = split(strLine,"/")
> > arrIPAddress(2) = "www.soa.org"
> > For Each item in arrIPAddress
> > MyOutputFile.Writeline(item & "/")
> > i = i + 1
> > Next
> > End If
> > Loop



Re: For Each loop writing on same line by pooradmin

pooradmin
Tue Nov 27 13:15:50 PST 2007

On Nov 27, 3:20 pm, Sheel <Sh...@discussions.microsoft.com> wrote:
> Just an update, I have figured out the printing out of each URL into the same
> line, but the trailing slash at the end of the output file is still a
> problem. Also, to add a little bit of complexity, the possibility of a URL
> string ending in a folder path does exist.
>
> http://www.sheel.com/this/is/only/atest.pdfbecomeshttp://new.sheel.com/this/is/only/atest.pdf/ <-- don't want that last slash
> after .pdf
>
> Thanks again in advance!
> Sheel
>
>
>
> "Sheel" wrote:
> > Hello,
>
> > I have a script where I read an input file, which contains a bunch of URL
> > strings of differing sizes. I split each element into an array based on the
> > slash ("/"). After that, I take one of the elements from the array, and
> > change it to another, and then put the URL string back together. The issue
> > I'm having is when I put it back together in a for each loop, it writes each
> > element onto its own line. Also, at the end of the line it puts a slash at
> > the end. How can I get each element to print on the same line, also omitting
> > the final slash? Here's the snippet of my code that does all this work...
>
> > Any help is greatly appreciated!
> > Sheel
>
> > example of line in input file:http://www.sheel.com/this/is/only/atest.pdf
>
> > Set myInputFile = fso.OpenTextFile("<input file>", ForReading)
> > Set MyOutputFile = fso.CreateTextFile("<output file>", True)
>
> > Dim arrIPAddress
> > Dim orgSplitter
> > Dim i
>
> > i = 0
> > Do Until myInputFile.AtEndOfStream
> > strLine = myInputFile.ReadLine
> > If inStr(strLine, "/") Then
> > arrIPAddress = split(strLine,"/")
> > arrIPAddress(2) = "www.soa.org"
> > For Each item in arrIPAddress
> > MyOutputFile.Writeline(item & "/")
> > i = i + 1
> > Next
> > End If
> > Loop- Hide quoted text -
>
> - Show quoted text -

Since you're just Splitting a string, replacing one value in the
array, you may be better off Joining it back together instead of
looping through. This would also put the slash back at the end if
it's there to begin with and leave it if not.

If inStr(strLine, "/") Then
arrIPAddress = split(strLine,"/")
arrIPAddress(2) = "www.soa.org"

sTemp = Join(arrIPAddress,"/")
MyOutputFile.WriteLine sTemp

End If
wscript.echo ""



-J
www.pooradmin.com