+ 1

Does somebody know how to ignore the rest of a string after a certain word?

So I want to make a command for a Discord Bot. The problem is that I want him to react to the command, but after the command is a sentence like: "#oracle Can I get rich?" something like this but it does not react to the command because of the sentence. I can`t remove the sentence because the command would be useless without it. This is the current code: Random random = new Random(); string[] oracle = new string[] { "Yes!", "No!", "Maybe!" }; commands.CreateCommand("Oracle").Do(async (e) => { await e.Channel.SendMessage("The answer is: " + oracle[random.Next(2)] ); }); Does anyone know how to solve this? Thanks for every answer ^^

23rd Mar 2017, 5:05 PM
Arelion
Arelion - avatar
2 Respuestas
+ 2
You can use if condition statement for checking the word and when you get it you can use the substring method
25th Mar 2017, 5:20 PM
Abhishek Chatterjee
Abhishek Chatterjee - avatar
0
Not sure if this is what you are after? But have you tried the contains for strings? { Random rnd1 = new Random(); string[] Answers = { "Yes", "No", "Maybe"}; string sometext = Console.ReadLine(); bool yesno = sometext.Contains("Oracle"); if (yesno) { Console.WriteLine(Answers[rnd1.Next(2)]); Console.ReadLine(); } else { Console.WriteLine("Whatever"); Console.ReadLine(); } Hope this helps, if not please post your answer just interested to know.
26th Mar 2017, 7:49 AM
chris