たとえば、Web の .txt ファイルから次の文字列をダウンロードしたとします。
line1
line2
line3
文字列全体を行ごとに分割するにはどうすればよいでしょうか? ありがとう!
使ってもいいですか?
string[] tokens = Regex.Split(input, @"\r?\n|\r");
ありがとう
たとえば、Web の .txt ファイルから次の文字列をダウンロードしたとします。
line1
line2
line3
文字列全体を行ごとに分割するにはどうすればよいでしょうか? ありがとう!
使ってもいいですか?
string[] tokens = Regex.Split(input, @"\r?\n|\r");
ありがとう
すべての行File.ReadAllLines
を取得するために使用します。string[]
string[] allLines = File.ReadAllLines(path);
string line10 = allLines[9]; // exception if there are less
string line100 = allLines.ElementAtOrDefault(99); // null if there are less
使用できる文字列が既にある場合はString.Split
、Environment.NewLine
string[] textLines = text.Split(new[]{ Environment.NewLine }, StringSplitOptions.None);
ファイルをダウンロードしている場合は、それを開いてReadAllLines
var f= File.ReadAllLines(filPath)
ReadAllLines
戻りますstring[]
。