TEXT文件读取错误!!! [英] TEXT File Reading Error!!!

查看:81
本文介绍了TEXT文件读取错误!!!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

阅读文本文件时遇到问题.我所做的是我从用户Webform获得了某些详细信息.我曾经通过"MULTILINE"文本框获取客户地址.
例如:

100号,
75/A座,
尼尔森路,
纽约,
美国.

然后在生成文本文件后,我曾经从特定的文本文件中读取数据并将这些数据添加到数据库中.
例如:


I face a problem when i read text Files. what i did is i get certain details from the user Webform. i used to get customer Address via "MULTILINE" Textbox.
EX:

NO.100,
BLOCK 75/A,
Nelson Road,
New York,
USA.

Then after generating Text File i used to read data from particular text file and add those data into the database.(EDI purpose).But when i used perticuler type of address the EDi did not reads feilds after the address feild and it returns NULL values
EX:


parameters[8] = BAL.CSV_temp.newTable1.Rows[i].ItemArray[5].ToString();
                    parameters[9] = BAL.CSV_temp.newTable1.Rows[i].ItemArray[6].ToString();
                    parameters[10] = common.selectCountry(BAL.CSV_temp.newTable1.Rows[i].ItemArray[7].ToString());
                    parameters[11] = common.selectDefaultCustomer();
                    parameters[12] = BAL.CSV_temp.newTable1.Rows[i].ItemArray[8].ToString();
                    parameters[13] = BAL.CSV_temp.newTable1.Rows[i].ItemArray[9].ToString();
                    parameters[14] = BAL.CSV_temp.newTable1.Rows[i].ItemArray[10].ToString();
                    parameters[15] = BAL.CSV_temp.newTable1.Rows[i].ItemArray[11].ToString();






但是当我按以下方式放置地址(单行)时,它可以完美地从文本文件中读取.


美国纽约州尼尔森路75号/A座100号.


有谁有解决这个问题的想法.是否有任何方法可以将MULTILINE文本转换为如上所述的单行?






But when i put the Address as a following way(In single line) it reads perfectly from the Text File.


NO.100,BLOCK 75/A,Nelson Road,New York, USA.


Does anyone have a idea to solve this problem. if there any way to CONVERT that MULTILINE text to a single line as mentioned above? thanks in advance!!!

推荐答案

看看string.Join:
string[] lines = { "line1,", "line2,", "line3," };
string s = string.Join("", lines);


string txt = txtMulti.Text.Replace(Environment.NewLine, " ");//one empty space
MessageBox.Show(txt);


如果您想从.txt文件中读取内容,则下面的代码会有所帮助

If u want to read from .txt file then below code will help

public static DataTable exceldata(string filePath)
        {     
         
        DataTable dtexcel = new DataTable();
       var filename = filePath;
                 var reader = ReadAsLines(filename);
                 // var data = new DataTable();
                 //This assume the first record is filled with the column names
                 var headers = reader.First().Split('\t');
                 foreach (var header in headers)
                 {
                     dtexcel.Columns.Add(header);
                 }
                 var records = reader.Skip(1);
                 foreach (var record in records)
                 {
                     dtexcel.Rows.Add(record.Split('\t'));
                 }
}







static IEnumerable<string> ReadAsLines(string filename)
        {
            using (var reader = new StreamReader(filename))
                while (!reader.EndOfStream)
                    yield return reader.ReadLine();
        }


这篇关于TEXT文件读取错误!!!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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