我正在尝试删除从文本文件中读取的块注释。所以'/ '和' /'之间的所有文本都应该被删除。读者逐行阅读问题所在。这就是我到目前为止所拥有的:
StringBuilder buildString = new StringBuilder();
using (StreamReader readFile = new StreamReader(filePath))
{
string line;
// reads the file line by line
while ((line = readFile.ReadLine()) != null)
{
//replaces the line if it has "--" in it.
line = Regex.Replace(line, @"--.*$", "");
if (line.StartsWith("/*"))
{
while ((line = readFile.ReadLine() ) != null)
{
//remove line untill the last line '*/'
if (line.StartsWith("*/"))
{
//Then Stop removing lines and go back to the main while.
}
}
}
buildString.Append(line + Environment.NewLine);
}
有什么建议或帮助吗?谢谢