using System.IO; StreamReader sr = new StreamReader(@"E:\WebPage\2011-04-12\248808221\250167153.txt");//你的txt文件路径 string rowstring = ""; while (sr.Peek() > 0) { rowstring = sr.ReadLine();// 获取当前行字符串 string str1=rowstring.SubString(0,3);// if(str1="你要的数字") { string str2=rowstring.SubString()//截取后面的字符串 break; } } sr.Close();
引用楼上修改 using System.IO; StreamReader sr = new StreamReader(@"E:\WebPage\2011-04-12\248808221\250167153.txt");//你的txt文件路径 string line = string.Empty; string result = string.Empty; while (sr.Peek() > 0) { line = sr.ReadLine();// 获取当前行字符串
if(line.StartWith("001")) { result = line.SubString(4);//截取后面的字符串 break; } } sr.Close();
字符串截取,你先把文件内容读取到dataset再截取
我是这么写的 public string CorName(string ) { StreamReader sr = new StreamReader("ll.txt", Encoding.Default); while (sr.Peek() >= 0) { ..... return ; } return errorr; }
using System.IO;
StreamReader sr = new StreamReader(@"E:\WebPage\2011-04-12\248808221\250167153.txt");//你的txt文件路径
string rowstring = "";
while (sr.Peek() > 0)
{
rowstring = sr.ReadLine();// 获取当前行字符串
string str1=rowstring.SubString(0,3);//
if(str1="你要的数字")
{
string str2=rowstring.SubString()//截取后面的字符串
break;
}
}
sr.Close();
using System.IO;
StreamReader sr = new StreamReader(@"E:\WebPage\2011-04-12\248808221\250167153.txt");//你的txt文件路径
string line = string.Empty;
string result = string.Empty;
while (sr.Peek() > 0)
{
line = sr.ReadLine();// 获取当前行字符串
if(line.StartWith("001"))
{
result = line.SubString(4);//截取后面的字符串
break;
}
}
sr.Close();
public string CorName(string ) {
StreamReader sr = new StreamReader("ll.txt", Encoding.Default);
while (sr.Peek() >= 0)
{
.....
return ;
}
return errorr;
}