textBox1にファイルを読み込んでそこから特定の行だけ別なtextBox2で表示させたいのですがうまく抜き出すことができません。
また一行ずつ読み込みたいのですがMessageBoxで確認したところ読み込まれない行があります。
textBox1へは正しくファイルが読み込まれています。
コードの間違いがありましたら教えていただきたいです。
C#
1using System; 2using System.Collections.Generic; 3using System.ComponentModel; 4using System.Data; 5using System.Drawing; 6using System.Linq; 7using System.Text; 8using System.Threading.Tasks; 9using System.Windows.Forms; 10using System.IO; 11 12namespace WindowsFormsApplication1 13{ 14 public partial class Form1 : Form 15 { 16 public Form1() 17 { 18 InitializeComponent(); 19 } 20 21 private void button1_Click(object sender, EventArgs e) 22 { 23 System.IO.StreamReader cReader = ( 24 new System.IO.StreamReader(@"C:\filename.xml", System.Text.Encoding.Default)); 25 26 string stResult = string.Empty; 27 28 while (cReader.Peek() >= 0) 29 { 30 string stBuffer = cReader.ReadLine(); 31 stResult += stBuffer + System.Environment.NewLine; 32 } 33 34 cReader.Close(); 35 36 textBox1.ScrollBars = ScrollBars.Both; 37 textBox1.Text = stResult; 38 } 39 40 private void button2_Click(object sender, EventArgs e) 41 { 42 System.IO.StringReader convert_st 43 = new System.IO.StringReader(textBox1.Text); 44 45 while (convert_st.Peek() > -1) 46 { 47 MessageBox.Show(convert_st.ReadLine()); 48 49 if ((convert_st.ReadLine()).StartsWith("<time>")) 50 { 51 textBox2.Text += (convert_st.ReadLine()); 52 textBox2.Text += "\r\n"; 53 } 54 } 55 convert_st.Close(); 56 57 58 } 59 } 60} 61
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/06/20 02:52