请教各位,我想逐行读取文本框中的内容,当遇到文本框中以T字母打头时行时,读取这一行的内容,要怎么实现啊,多谢帮忙啦!
文本框中内容大致为:
D12345667
T2355678900--
A235678990SSDFGHU7
T234567890000--II
...
...
文本框中内容大致为:
D12345667
T2355678900--
A235678990SSDFGHU7
T234567890000--II
...
...
str.split('\n'),然后遍历数组吧
{
...
}
{
string s = @"D12345667
T2355678900--
A235678990SSDFGHU7
T234567890000--II";
string[] ss=s.Split('\n');
foreach (string s2 in ss)
{
if (s2.Trim().StartsWith("T"))
{
ftWinCommon.MsgBox(s2);
}
}
}
string[] str = textBox1.Text.Split['\n'];
for (int i = 0; i < str.Length; i++)
{
if (str[i].Substring(0, 1) == "T")
{
MessageBox.Show(str[i]);//取出T开头的行
}
}
just like this ...
StringBuilder sb = new StringBuilder();
sb.AppendLine("D12345667");
sb.AppendLine("T2355678900");
sb.AppendLine("A235678990SSDFGHU7");
sb.AppendLine("T234567890000--II");
foreach (string s3 in sb) //此处不行
{ }
foreach(string data in st)
{
……ok啦
}
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader(@"D:\新建文本文档.txt"))
{
String line;
// Read and display lines from the file until the end of
// the file is reached.
while ((line = sr.ReadLine()) != null && (line = sr.ReadLine()).StartsWith("T"))
{
Console.WriteLine(line);
}
}
}
catch (Exception e)
{
// Let the user know what went wrong.
Console.WriteLine("The file could not be read:");
Console.WriteLine(e.Message);
}
{
string s = @"D12345667
T2355678900--
A235678990SSDFGHU7
T234567890000--II";
string[] ss=s.Split('\n');
foreach (string s2 in ss)
{
if (s2.Trim().StartsWith("T"))
{
ftWinCommon.MsgBox(s2);
}
}
}
{
}
不太明白,望指点指点,不甚感激啊