Solved

ASP ReadLine: Detect Format Of Line Breaks

Posted on 2010-08-25
6
866 Views
Last Modified: 2013-09-25
My users are uploading a TXT file and I am using the following code:

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

Open in new window


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:

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

Open in new window


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!
0
Comment
Question by:djlurch
  • 3
  • 2
6 Comments
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 33527115
>>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:
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

Open in new window

0
 
LVL 1

Author Comment

by:djlurch
ID: 33527752
Interesting.

Unfortunately, I will not know which format they are using. I need to detect it server side. Possibly this will work:

If InStr(strContents,chr(13) & chr(10)) > 0 Then
   format = win
ElseIf InStr(strContents,chr(13)) > 0 Then
   format = mac
Else
   format = unx
End If


0
 
LVL 1

Author Comment

by:djlurch
ID: 33527791
Nevermind...re-read your post and figured it out.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 82

Expert Comment

by:hielo
ID: 33535056
What I posted should work, regardless of which platform they are uploading from. Whatever it is that you were attempting to do with a line of text, would now be done at the place where I have:
'do whatever with it...

where "it" refers to lines(i) which is a line of text

Regards,
Hielo
0
 
LVL 1

Author Closing Comment

by:djlurch
ID: 33535223
Elegant solution. Thanks!
0
 

Expert Comment

by:mharzl
ID: 39521500
Line 15 is wrong

If UBound(r)=0 Then

should be

If UBound(lines)=0 Then
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:  The Exchange of information …
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now