Question : ASP ReadLine: Detect Format Of Line Breaks

My users are uploading a TXT file and I am using the following code:

1:
2:
3:
4:
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")	
Set objFile = objFSO.OpenTextFile(strFilePath,1,False,-1)
Line = objFile.ReadLine


The problem is that some are uploading a Mac text file and some are uploading a PC text file. A Hex compare of the files indicates that the EOL is 0A in one and 0D in the other.

First off, what is the proper name for each the formats?

Secondly, how can determine which is which via Classic ASP?

I tried changing x to 0,-1,-2 in the following:

1:
Set objFile = objFSO.OpenTextFile(strFilePath,1,False,x)


Ultimately, when I do a readline for the Mac formatted file, the Line contains the whole text file instead of just one line like when I use a PC formatted file.

Thanks in advance for your assistance!

Answer : ASP ReadLine: Detect Format Of Line Breaks

>>First off, what is the proper name for each the formats?
They are not different formats. What you are experiencing is just cross-platform incompatibilities.
Each of the major platforms use different characters as a newline delimiter.

Try the following:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
Dim strContents,lines,win,mac,unx
'delimiters for the various platforms
win=chr(13) & chr(10)
mac=chr(13)
unx=chr(10)

Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strFilePath, ForReading)
strContents = objFile.ReadAll

lines=Split(strContents,win)
If UBound(lines)=0 Then
	lines=Split(strContents,unx)
	If UBound(r)=0 Then
		lines=Split(strContents,mac)
	End If
End If
objFile.Close

For i=0 TO UBound(lines)
	'lines(i) will hold the line content
	'do whatever with it...
Next
Random Solutions  
 
programming4us programming4us