不能单独的文本文件通过分隔符| [英] Can't Separate Text File By Delimiter |
问题描述
我使用C#。
我想在一个文本文件为对象来拉。我使用的是ODBC连接,它看起来像这样
I am trying to pull in a text file to an object. I am using an ODBC connection and it looks like this
驱动= {Microsoft文本驱动程序(* .TXT; * .csv的)}; DBQ = C:\Users \Owner\Desktop\IR\IR_Files\Absolute;扩展= ASC,csv,选项卡,TXT;
Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=C:\Users\Owner\Desktop\IR\IR_Files\Absolute;Extensions=asc,csv,tab,txt;
我能够进行连接,但我不能让我的列分开。我使用的是schema.ini文件,但它不工作。这里是我的架构文件
I am able to make the connection but I can't get my columns separated. I'm using a schema.ini file but it isn't working. Here is my schema file.
[MyTextFile.CSV]
格式=分隔(|)
ColNameHeader =假
COL1 = fullstockn文本
COL2 = FULLINFO文字
的MaxScanRows = 0
CHARACTERSET = ANSI
[MyTextFile.CSV]
Format=Delimited(|)
ColNameHeader=False
Col1=fullstockn Text
col2=FULLINFO Text
MaxScanRows=0
CharacterSet=ANSI
该文本文件看起来像这样。
The text file looks like this.
fullstockn | FULLINFO
fullstockn|FULLINFO
555555|
Contenu:新桥Ttudes SUR L这里一些文字......
"555555 "|
Contenu : Neuf Ttudes sur l Some more text here.....
推荐答案
我用下面的连接字符串
string connectionString = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=\"text;HDR=YES;Format=Delimited(|)\";", Path.GetDirectoryName(path));
和通常开始
[myFile.txt]
Format=Delimited(|)
TextDelimiter="none"
和我会通过
command.CommandText = String.Format("SELECT * FROM [{0}]", Path.GetFileName(path));
OleDbDataReader reader = command.ExecuteReader();
此外,的上的文本文件驱动程序MSDN页面是有益的,当我第一次调查这一点。具体来说,在的Schema.ini的页面
文件是非常有用的。
Also, the MSDN page on the text file driver was helpful when I first investigated this. Specifically, the page on the Schema.ini
file is quite useful.
这篇关于不能单独的文本文件通过分隔符|的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!