Helo to all。我有一个名为mytext.txt的文本文件,文本内部的格式如下:
<name1>Myname
age
address
postal code
<name2>Myname
age
address
postal code
....(more of the same)
我遇到的问题是我必须在richTextBox中打印此文本,格式如下:
<name1>Myname
-age
-address
-postal code
<name2>Myname
-age
-address
-postal code
....(more of the same)
任何想法我必须如何做到这一点?
答案 0 :(得分:3)
我不会给你确切的代码,但我可以给你一个伪代码表示工作算法的样子:
function printTextFile()
{
for(every line in the text file)
// So start the loop through each line.
if(current line does not start with "<")
{
prefix:= " -".
// So we're not at a title part.
}
print(prefix + current line).
// Print out the line with the indent.
prefix:= "".
// reset the prefix.
end for loop.
}
答案 1 :(得分:0)
var writer = new StringBuilder();
foreach (var line in File.ReadAllLines("mytext.txt"))
{
writer.AppendLine(!line.StartsWith("<") ? string.Format(" -{0}", line) : line);
}
richTextBox1.Text = writer.ToString();