나는 그들이 내가 가진 문제를 가지고 가정 (자신의 문제에 도움을 필요로 다른 사람을 위해 여기에 코드를 가져온 거에요 를 수정했습니다. IRC 채팅 명령 구문 분석
FIXED CODE THAT WORKS
public static bool CommandExists(String value)
{
string[] commands = File.ReadAllText("commands.txt")
.Split()
.Where(x => x.StartsWith(value))
.Distinct()
.ToArray();
return commands.Contains(value);
}
public static string CommandParse(String value, string nick)
{
IEnumerable<string> lines;
lines = File.ReadLines("commands.txt");
IEnumerable<string> command = lines
.Where(d => d.StartsWith(value,
StringComparison.CurrentCultureIgnoreCase));
foreach (string line in command) {
string vals = line
.Replace("@nick", nick)
.Replace("@upnick", nick.ToUpper())
.Replace(value + " ", "");
return vals;
}
return null;
}
그래서 내가 봤는데 몇 시간 동안 노력하고 나는 주변을 둘러 보았고 내가하려는 일과 관련된 것을 찾을 수 없었다.
나는 "commands.txt"라는 텍스트 파일을 가지고 있는데 나는 노력하고있다. 텍스트를 파싱합니다. 내용은 다음과 같습니다.
!ver Testing this
!help Hello, current commands are: !help, !ver
지금 나는 '배열의 범위를 벗어난 인덱스'를 얻을string x1 = File.ReadAllLines("commands.txt").ToString(); string[] x2 = x1.Split(' '); string x3 = x2[0]; Console.WriteLine(x3);
당기면. 나는 내가 뭘 잘못하고 있는지 전혀 모른다. 명령이있는 경우 또한 호출 할 '정적 부울'를 사용하기 위해 노력하고있어 지금까지 내가
public static bool CommandExists(String value) { if (File.ReadAllLines("commands.txt").Contains(value.ToString())) { return true; } else { return false; } }
을 가지고 그뿐만 아니라 작동하지 않습니다.
해당 예외의 원인은 무엇입니까?
편집 : CommandParse()
public static string CommandParse(string value, string nick) { string[] commands = File.ReadAllText("commands.txt") .Split() .Where(x => x.StartsWith("!"+value.ToLower())) .Distinct() .ToArray(); string cmd = commands[1] .Replace("@nick", nick) .Replace("@nickup", nick.ToUpper()); return cmd; }
가 지금은 True를 반환 것을 알고 어떻게 그렇지 명령 자체를 true를 반환하지만 반환받을 수 있나요
포럼 사이트와 달리, 우리는 "감사"또는 "도움을 주셨으면"또는 [그래서]의 서명을 사용하지 않습니다. [Hi, 감사, 태그 라인 및 인사말을 게시물에서 삭제해야합니까?] (http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be- 게시물에서 삭제됨). – rene