将数据从文本框传输到流读取器
我是 c# 新手 在此之前,我尝试让流读取器读取文本框中的结束数据。 现在...我尝试将数据从文本框逐行移动到另一个流读取器 我尝试这个代码
String filename = ContentBox.Text;
if (File.Exists(filename))
{
using (StreamReader fileReader = new StreamReader(filename))
{
String fileRow = "";
while ((fileRow = fileReader.ReadLine()) != null)
{
String[] fileDataField = fileRow.Split(new string[] { "\r\n\t", " " }, StringSplitOptions.RemoveEmptyEntries);
String ListSplitLineByLine = "";
//line = line.Replace("\r\n", " ");
//String[] SplitItemLineByLine1 = (line).Split(' ');
foreach (string lineByLine in fileDataField)
{
ListSplitLineByLine += "\r\n" + lineByLine;
}
txtCaseInputs.Text = ListSplitLineByLine.Trim();
GenCombItems();
}
//Close the StreamReader
fileReader.Close();
}
}
这没有错误,但是当我运行时没有任何错误...... 是我的编码错误吗?
i'm new with c#
before this i try that streamreader read to end data in textbox.
now...i'm try to move data from textbox to another streamreader line by line
i try this code
String filename = ContentBox.Text;
if (File.Exists(filename))
{
using (StreamReader fileReader = new StreamReader(filename))
{
String fileRow = "";
while ((fileRow = fileReader.ReadLine()) != null)
{
String[] fileDataField = fileRow.Split(new string[] { "\r\n\t", " " }, StringSplitOptions.RemoveEmptyEntries);
String ListSplitLineByLine = "";
//line = line.Replace("\r\n", " ");
//String[] SplitItemLineByLine1 = (line).Split(' ');
foreach (string lineByLine in fileDataField)
{
ListSplitLineByLine += "\r\n" + lineByLine;
}
txtCaseInputs.Text = ListSplitLineByLine.Trim();
GenCombItems();
}
//Close the StreamReader
fileReader.Close();
}
}
it is no error but when i run there is nothing...
is it my coding error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在每次迭代中,您将该迭代的结果分配给 txtCaseInputs.Text,“覆盖”上一次迭代的结果。
如果您希望文本框包含文件中所有字段的串联,则应在每次迭代中附加而不是分配:
并且不要忘记在开始整个过程之前清除文本框的内容。
On each iteration, you assign that iteration's result to
txtCaseInputs.Text
, writing "over" the previous iteration's result.If you want the textbox to contain concatenation of all fields from the file, you should append on each iteration instead of assigning:
And don't forget to clear the textbox's contents before starting the whole process.
在那里放置一些调试语句,直到它正常工作为止。
您稍后可以随时删除它们。
Put a few debug statements in there until you get it working right.
You can always remove them later.