如何从ASP.NET中的文本文件获取数据 [英] How to get data from a text file in asp .NET
本文介绍了如何从ASP.NET中的文本文件获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我想从asp.Net项目中的文本文件中获取数据.
如:
SKU# 产品说明 手册.代码 数量 单价
1. 10071420 Kesir-钙华瓷砖18CB 83盒(933.75平方呎)$ 1.970/平方呎
Denizli米色/18"x18" x1/2"
有谁知道该怎么做吗?
问候
Haluk
Hello guys,
I would like to get data from a text file in asp.Net project.
Such as:
SKU# Product Description Manu. Code Quantity Unit Price
1 . 10071420 Kesir - Travertine Tiles 18CB 83 boxes (933.75 sq ft) $1.970 /sq ft
Denizli Beige / 18"x18"x1/2"
Is there anyone who knows how to do that?
Regards
Haluk
推荐答案
1.970/sq ft
Denizli米色/18"x18" x1/2"
有谁知道该怎么做吗?
问候
Haluk
1.970 /sq ft
Denizli Beige / 18"x18"x1/2"
Is there anyone who knows how to do that?
Regards
Haluk
您对此有何看法:
What do you think about it:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace ReadTextFile
{
class ReadText
{
static void Main(string[] args)
{
//- Location of the Text file
string fileName = @"c:temptxt_test.TXT";
//- Set the line counter
int lineNumber = 0;
//- Write initial text to the console
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
Console.WriteLine("MY FAVORITE SONGS");
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
//- Open the text file
using (StreamReader sr = new StreamReader(fileName))
{
//- Initialize name variables
string aName = "";
string sName = "";
string alName = "";
string line; //- Holds the entire line
//- Cycle thru the text file 1 line at a time pulling
//- substrings into the variables initialized above
while ((line = sr.ReadLine()) != null)
{
lineNumber++;
//- Pulling substrings. If there is a problem
//- with the start index and/or the length values
//- an exception is thrown
try
{
aName = line.Substring(0,21).Trim();
sName = line.Substring(22,25).Trim();
alName = line.Substring(47,17).Trim();
}
catch (Exception ex)
{
Console.Write(ex.ToString());
}
//- Write the information to the console
Console.WriteLine("Artist: {0}", aName);
Console.WriteLine("Title : {0}", sName);
Console.WriteLine("Album : {0}", alName);
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
}
sr.Close();
}
}
}
}
选中此项.
http://www.aspdotnet-suresh. com/2010/12/how-to-read-and-write-text-file-using.html [ http://www.gridview.net/read-text-file-in-c -asp-net/ [ ^ ]
Check this.
http://www.aspdotnet-suresh.com/2010/12/how-to-read-and-write-text-file-using.html[^]
http://www.gridview.net/read-text-file-in-c-asp-net/[^]
这篇关于如何从ASP.NET中的文本文件获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文