ASP的ReadLine非标行尾 [英] ASP Readline non-standard Line Endings

查看:88
本文介绍了ASP的ReadLine非标行尾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的文件系统对象的ASP经典的ReadLine()函数。所有一直很大,直到有人取得了文本编辑在Mac上的导入文件。该行结束是不一样的,和readline()一次读取整个文件,而不只是1行。

I'm using the ASP Classic ReadLine() function of the File System Object. All has been working great until someone made their import file on a Mac in TextEdit. The line endings aren't the same, and ReadLine() reads in the entire file, not just 1 line at a time.

是否有处理这种标准方式吗?一些页面指令,或在文件系统对象设置?

Is there a standard way of handling this? Some sort of page directive, or setting on the File System Object?

我想,我可以在整个文件中读取,并在vbLF分裂,然后对每个项目,以替换VBCR,然后处理线,一次一个,但似乎有点缺憾。

I guess that I COULD read in the entire file, and split on vbLF, then for each item, replace vbCR with "", then process the lines, one at a time, but that seems a bit kludgy.

我已经找遍了一个解决这个问题,但解决方案都是沿着线不保存与Mac [原文]行结尾的文件。

I have searched all over for a solution to this issue, but the solutions are all along the lines of "don't save the file with Mac[sic] line endings."

任何人有处理这个问题的一个更好的办法?

Anyone have a better way of dealing with this problem?

推荐答案

有没有办法更改的ReadLine 的行为,它只能识别CRLF作为行结束。因此,只有简单的解决办法是你已经描述的。

There is no way to change the behaviour of ReadLine, it will only recognize CRLF as a line terminator. Hence the only simply solution is the one you have already described.

修改

其实还有另外一个库,应该是提供开箱即可能会提供一些​​帮助的ASP服务器上。这是ADODB库

Actually there is another library that ought to be available out of the box on an ASP server that might offer some help. That is the ADODB library.

的ADODB.Stream 对象有可分配10或13来覆盖默认CRLF一个 LineSeparator 属性它通常会使用。该文档是不完整,因为它并没有描述如何可以用 READTEXT 使用。你可以在 READTEXT 方法传递-2作为它的参数,返回从流的下一行。

The ADODB.Stream object has a LineSeparator property that can be assigned 10 or 13 to override the default CRLF it would normally use. The documentation is patchy because it doesn't describe how this can be used with ReadText. You can get the ReadText method to return the next line from the stream by passing -2 as its parameter.

在这个例子看看: -

Take a look at this example:-

Dim sLine
Dim oStreamIn : Set oStreamIn = CreateObject("ADODB.Stream")

oStreamIn.Type = 2 '' # Text
oStreamIn.Open 
oStreamIn.CharSet = "Windows-1252"
oStreamIn.LoadFromFile "C:\temp\test.txt"
oStreamIn.LineSeparator = 10 '' # Linefeed

Do Until oStreamIn.EOS
  sLine = oStreamIn.ReadText(-2)
  '' # Do stuff with sLine
Loop

oStreamIn.Close

请注意,默认情况下是字符集UNI code,所以你将需要分配正确的字符集正在使用的文件,如果它不是统一code。我用的是统一code在这个意义上,该文件确实这实际上意味着UTF-16。这里的一个优势是,ADODB流可以处理UTF-8不像脚本库。

Note that by default the CharSet is unicode so you will need to assign the correct CharSet being used by the file if its not Unicode. I use the word "Unicode" in the sense that the documentation does which actually means UTF-16. One advantage here is that ADODB Stream can handle UTF-8 unlike the Scripting library.

顺便说一句,我还以为互助用于行结束一个CR?使用它的LF Unix文件格式是不是?

BTW, I thought MACs used a CR for line endings? Its Unix file format that uses LFs isn't it?

这篇关于ASP的ReadLine非标行尾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆