回答
下面是如何讀取文本文件的行一般:What's the fastest way to read a text file line-by-line?
你可以這樣做:
var lines = File.ReadAllLines(fileName);
int numLines = lines.Length;
for (int lineCounter = 1 /*discard the first*/;lineCounter<Length-1 /*discard the last*/;lineCounter++)
{
Do whatever you want with lines[lineCounter]
}
你可以使用ReadAllText
得到該文件的內容,然後Replace
和Trim
刪除該文件的內容無用:
var result = System.IO.File.ReadAllText(@"c:\path\to\file.txt")
.Replace("*", string.Empty) // remove the asterisks
.Trim(); // trim whitespace and newlines
如果你知道****計數,那麼這可能會有所幫助。
string readContents;
using (StreamReader streamReader = new StreamReader(path, Encoding.UTF8))
{
readContents = streamReader.ReadToEnd();
int start = readContents.IndexOf("*****") + 1;
int end = readContents.LastIndexOf("*****", start);
string result = readContents.Substring(start, end - start);
}
這會還讀了*******行 –
@MartinBrown代碼更新了。請檢查 –
不行,仍然不起作用。假設文件中包含「***** \ r \ nSome Text \ r \ n *** **「。變量'start'最終爲1. LastIndex然後在結尾爲1的字符串中查找」*****「,即它在」*「中查找」*****「。'結束「然後變成-1使子字符串失敗。 –
- 1. 2個模式之間的提取線
- 2. 我如何找到2線段之間的交點座標C++
- 3. A和(B或C)之間的提取線,包含D
- 4. 在2格之間畫一條線
- 5. 如何提取圖案之間的線條?
- 6. 如何提取多行模式之間的線條?
- 7. 如何使用java模式提取模式之間的線?
- 8. 如何提取兩條斜線PHP之間串
- 9. 提取線新線
- 10. 在2種形式之間傳遞變量,多線程C#
- 11. 如何在畫布上繪製2點之間的曲線?
- 12. Android如何在2點之間繪製線條
- 13. 如何比較畫線是否在2組數值之間
- 14. 如何在2個線程之間共享變量
- 15. 如何在Bootstrap的2列之間添加水平線
- 16. 如何提取「線」的Android
- 17. 提高2個線程之間的事件,當兩個線程是一個WinForm
- 18. C++ - 在線程之間共享數據
- 19. 如何在圓圈之間畫線?
- 20. 如何在線程之間傳輸鎖?
- 21. 如何在兩點之間畫線?
- 22. MapKit - 2針之間的繪製線
- 23. 2個對象之間的相交線
- 24. 2個線程之間的交替
- 25. 功能2之間GPS座標線
- 26. 2條相交線之間的像素
- 27. 表之間線
- 28. Android的谷歌地圖V2:如何讓2點之間的折線是曲線
- 29. C#線程 - 在線程之間發佈消息
- 30. 在線程之間共享不帶鎖的線程值C
讀每一行,尋找線= *****」,過程下一行,看着每一個,直到你看到‘****’再次 – pm100
我的意思是,RLY,寫一些代碼 – pm100