我想從C#中的輸入文件中讀取數據。以下是我的代碼。通過指定起點和終點從文件中讀取
public string ReadFromNewEntityFile()
{
string template=null;
StringBuilder s = new StringBuilder();
//char[] sourcesystemhost=null;
string inputFileName = ConfigurationManager.AppSettings["inputNewEntityFilePath"].ToString();
System.IO.StreamReader myFile;
try
{
myFile = new System.IO.StreamReader(inputFileName);
myFile.ReadLine();
while ((template = myFile.ReadLine()) != "[[END SourceSystemHost]]")
{
s.AppendLine(template);
}
}
catch (Exception ex)
{
log.Error("In Filehandler class :" + ex.Message);
throw new Exception("Input file not read" + ex.Message);
}
return template;
}
問題是想要指定讀取內容的起點和終點。在這裏,我只能指定終點。我如何指定起點?
請幫
是以字節,行或字符指定的起始點嗎?或通過一個sentinel字符串?它很重要 –
@MarcGravell哇..非常好。我剛剛發佈了一個「Seek」示例..我真的得更好地尋求這樣的澄清。 –
請不要在標題中包含languge標籤,除非在沒有標籤的情況下才有意義。標籤用於此目的。 –