C# StreamReader的问题
好的,这是我到目前为止得到的C# StreamReader的问题,c#,streamreader,networkstream,C#,Streamreader,Networkstream,好的,这是我到目前为止得到的 List<string> lines = new List<string>(); using (StreamReader r = new StreamReader(f)) { string line; while ((line = r.ReadLine()) != null) { lines.Add(line); } } foreach (string s in lines) { N
List<string> lines = new List<string>();
using (StreamReader r = new StreamReader(f))
{
string line;
while ((line = r.ReadLine()) != null)
{
lines.Add(line);
}
}
foreach (string s in lines)
{
NetworkStream stream = irc.GetStream();
writer.WriteLine(USER);
writer.Flush();
writer.WriteLine("NICK " + NICK);
writer.Flush();
writer.WriteLine("JOIN " + s);
writer.Flush();
string trimmedString = string.Empty;
CHANNEL = s;
}
这是向IRC写的唯一方法,那么有没有办法让“频道”只作为文本的开头,只是#lol,这样它就不会写密码了
我希望你能理解我的问题。你可以在一个空格上拆分并拿走第一件物品:
CHANNEL = s.Split(' ')[0];
这将导致{“#lol”,“test”}
,尽管理想情况下会事先检查:
string input = "#lol test";
string channel = "";
string key = "";
if (input.Contains(" "))
{
string[] split = input.Split(' ');
channel = split[0];
key = split[1];
}
else
{
channel = input;
}
Console.WriteLine("Chan: {0}, Key: {1}", channel, key);
string input = "#lol test";
string channel = "";
string key = "";
if (input.Contains(" "))
{
string[] split = input.Split(' ');
channel = split[0];
key = split[1];
}
else
{
channel = input;
}
Console.WriteLine("Chan: {0}, Key: {1}", channel, key);
CHANNEL = s.Substring(0,s.IndexOf(" "));