Forum Moderators: open

Message Too Old, No Replies

how to exclude first line in a include file

         

laura2k

4:55 pm on Jun 19, 2004 (gmt 0)



Hi,

I am currently using the FileSystemObject to include a file and dynamically replace certain things using the replace() function. The include file i have has 3 lines, can anyone tell me how i can just skip the first line and read only the 2nd and 3rd.

Thanx in advanced.

ogletree

5:08 pm on Jun 19, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can use the right() function.

laura2k

5:55 pm on Jun 19, 2004 (gmt 0)



hi,

I dont know how this would work because the right function seems to require me to input a certain number of characters after which it should start. But the thing with my particular situation is that the length of the first line is very dynamic, sometimes it can be very short and sometimes it can be very short.

many thanx in advanced

Easy_Coder

6:42 pm on Jun 20, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Are you able to search for the first instance of vbCrLf?

duckhunter

11:23 pm on Jun 20, 2004 (gmt 0)

10+ Year Member



When you open the File with the FileSystem Object, use the ReadLine method and skip the first iteration. ie: Read one line at a time instead of a ReadAll method.

ogletree

2:59 am on Jun 21, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You can use the Len and InStr command to come up with the number to put into the Right command if there is anything that is contant. If the second part always starts with the same thing or first part ends in the same thing like a space or comma or anything.

laura2k

4:01 pm on Jun 21, 2004 (gmt 0)



can anyone actually give me an example please? i am a complete novice in asp and am quiet confused with all the suggestions made :(

thanx in advanced

laura2k

6:49 pm on Jun 21, 2004 (gmt 0)



i have just realised that the line that i want to exclude and remove from the text file contains the word "temp" so is there anyway just to search for a line that contains the word temp and delete that entire line and save the include file?

thanx in advanced.

duckhunter

8:20 pm on Jun 21, 2004 (gmt 0)

10+ Year Member



Here's a sample using my method. SkipLine before looping through the file

Dim fso, f

Set fso = server.CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile("c:\inetpub\wwwroot\Project1\test.txt")

'Skip the First Line
If Not f.AtEndOfStream Then
f.SkipLine
End If

'Now Loop through the remainder of the lines until EOF
Do While Not f.AtEndOfStream
sLineItem = f.ReadLine
Response.Write sLineItem & "<BR>"
Loop

f.close

dotme

8:22 pm on Jun 21, 2004 (gmt 0)

10+ Year Member



As with any coding, there are many ways to accomplish what you need to. The code snippet below will read a text file, and skip the first line. The result is then the variable "fulltext"

You can add <br> or vbcrlf after each line also if necessary, by modifying the

fulltext = fulltext & ts.readline

To, for example, fulltext = fulltext & vbcrlf & ts.readline

Hope this helps!

JD

-----------------------

Set fso = Server.CreateObject("Scripting.FileSystemObject")
filename = "C:\whatever\whatever.txt")
fulltext = ""
Set f = fso.GetFile(filename)
Set ts = f.OpenAsTextStream(1, -2)
i = 0
Do While Not ts.AtEndOfStream
i = i + 1
If i > 1 Then
fulltext = fulltext & ts.readline
End If
Loop
Set ts = Nothing
Set f = Nothing
Set FSO = Nothing