【发布时间】:2014-02-06 13:36:08
【问题描述】:
我有一个 for 循环来逐行读取流阅读器。这很好用。现在我在阅读流阅读器的文件时遇到了问题。这是一个包含两列信息的 csv 文件。第一个 (A) 包含一个 C# 元素,如文本框或标签(就像“label_1_title”),它在我的项目中声明。第二个(B)包含一个普通的简单字符串,如“Hello”。
现在我想将 A 列的字符串内容转换为真实存在的元素。示例:我在 A 列中写了“label_1_title”,这是一个元素,存在于我的项目中。现在我想使用这个元素来(例如)将它的内容更改为该行 B 列的内容。
public void SetSprachpaket(string Sprachpaket)
{
StreamReader StreamReader = new StreamReader(Sprachpaket, Encoding.UTF8);
string Inhalt = StreamReader.ReadLine();
for (int i = 1; Inhalt != null; i++)
{
var Items = Inhalt.Split(new Char[] { ';' });
object Element = Items[0].GetType(); // Convert the string content of Items[1] to the existing object
Element = Items[1]; // Take this existing object and give it the string content of Items[2]
Inhalt = StreamReader.ReadLine();
}
StreamReader.Close();
}
我希望你能帮助我。提前致谢。亲切的问候。
编辑:
object Element = Items[0].GetType(); // Get (let's say) the string "myString"
Element = Items[1]; // --> myString = ...
【问题讨论】:
-
你的项目是 ASP.NET、WinForms 还是 WPF?
-
Sprachpaket 的例子会很棒
标签: c# wpf string csv streamreader