比如说1.txt文件内容为
fromname: [email protected]
toname: [email protected]
True
admin: 李四
password: 123
CompanyName: fffff
CompanyAddress: fffff
Contacts: ffff
Phone: ffff
Fax: ffff
Email: [email protected]
Website: http://fffff2126.com现在我想用StreamReader sr = new StreamReader("E\1.txt",System.Text.Encoding.UTF8);
string strCompanyName = sr.Read()......
取得CompanyName:和右边的值fffff
fromname: [email protected]
toname: [email protected]
True
admin: 李四
password: 123
CompanyName: fffff
CompanyAddress: fffff
Contacts: ffff
Phone: ffff
Fax: ffff
Email: [email protected]
Website: http://fffff2126.com现在我想用StreamReader sr = new StreamReader("E\1.txt",System.Text.Encoding.UTF8);
string strCompanyName = sr.Read()......
取得CompanyName:和右边的值fffff
string str ="";
while((str=sr.ReadLine())!="")
{
if(str.indexof("CompanyName") >-1)
{
string name = str.split(':')[1];
break;
}
}
textBox2.txt = s[4];
using(StreamReader sr = new StreamReader("E\1.txt",System.Text.Encoding.UTF8))
{
str = sr.ReadLine();
}
......//继续你的操作
using(StreamReader sr = new StreamReader("E\1.txt",System.Text.Encoding.UTF8))
{ string str;
while((str=sr.ReadLine())!="")
{
if(str.indexof("CompanyName") >-1)
{
string name = str.split(':')[1];
break;
}
}
}
......//继续你的操作
CompanyAddress:中间的值。可以用indexof。
//偷了下懒
StreamReader sr = new StreamReader("E:/1.txt",System.Text.Encoding.UTF8);
string str = "";
int index;
//string[] left=new string[10];
//string[] right=new string[10];
string left;
string right;
while ((str=sr.ReadLine()) != "")
{
index = str.IndexOf(':');
if (index != -1)
{
left = str.Substring(0, index+1);
right = str.Substring(index+1, str.Length - index-1);
}
}