当我读取固定长度文件时,该值始终没有空格。
示例:文件夹 c:\temp 包含 2 个文件
fs.txt
ITMHMC12-163 -0000153430.30
ITMHMC12-164 -0000000745.18
架构.ini
[fs.txt]
ColNameHeader=False
Format=FixedLength
DateTimeFormat=yyyymmdd
Col1=RecordTypeSCFBody Text Width 3
Col2=InvoiceNumber Text Width 10
Col3=Amount Text Width 14
用于读取文件的 C# 代码...
string fileName = @"C:\temp\fs.txt";
string dir = Path.GetDirectoryName(fileName);
DataTable dataTable;
using (OleDbConnection conn =
new OleDbConnection(@"Provider=Microsoft.Jet.OleDb.4.0;" +
"Data Source=" + dir + ";" +
"Extended Properties=\"Text;\""))
{
conn.Open();
using (OleDbDataAdapter adapter = new OleDbDataAdapter("select * from " + fileName, conn))
{
dataTable = new DataTable();
adapter.Fill(dataTable);
}
conn.Close();
}
Console.Write(dataTable.Rows[0][1].ToString()); <-- this line **
-->这条线给了我“HMC12-163”,但我期待“HMC12-163”。注意空间!
感谢你的帮助。
非常感谢!-德布