我需要从ASP .NET中的文本文件中提取数据。编辑并从文本文件中提取数据(ASP .NET)
实施例的数据:
; comment
data = astringvalue
; comment
; string values
person = bob
animal = rabbit
; boolean values (yes/no)
isValid = yes
isAnimal = no
我将要创建的每个是不是一个注释行的GUI控制。 什么是提取每一行并确定它是字符串还是布尔值的最佳方式。 性能是必须的,因为该文件可能相当大。
编辑:在某些时候,我将需要更新网页中更新的值。
private void ShowConfig()
{
string configLine = String.Empty;
using (TextReader tr = File.OpenText(@"textfile"))
{
do
{
configLine = tr.ReadLine();
if (!String.IsNullOrEmpty(configLine) && !configLine.Contains(Convert.ToChar(";")))
{
CreateControl(configLine);
}
} while (configLine != null);
}
private void CreateControl(string configline)
{
string lineHeader = string.Empty;
string lineValue = String.Empty;
for (int i = 0; i < configline.Length; i++)
{
if (configline[i] == Convert.ToChar("="))
{
lineHeader = configline.Remove(i).TrimEnd();
lineValue = configline.Remove(0, ++i).TrimStart();
if (GetValueType(lineValue) is CheckBox)
{
this.Panel1.Controls.Add(CreateCheckBox(lineValue, lineHeader));
}
else
{
this.Panel1.Controls.Add(CreateLabel(lineHeader));
this.Panel1.Controls.Add(CreateTextBox(lineValue, lineHeader));
}
this.Panel1.Controls.Add(CreateNewLine());
break;
}
}
}
private Control GetValueType(string Value)
{
switch (Value)
{
case "yes":
case "no":
return new CheckBox();
default:
return new TextBox();
}
}
将来我需要检查更多的值类型比字符串和布尔值。
你尝试过什么?你能发布你的代码并解释你在哪里遇到困难吗? – Oded
这是我们的作业,或者你做了什么? – sikender
数据=值属于哪个类别?或者到底要做什么..不清楚 – V4Vendetta