Hack Forums
[C#] If textbox has a word then this happens - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] If textbox has a word then this happens (/showthread.php?tid=4550377)



If textbox has a word then this happens - Jack_Soff - Nov 22, 2014

ok I am pulling the source from a website and putting it into a textbox. I want to make it so that if the word "Troll" is anywhere in the textbox then something happens.

how would I do this? thanks


* - Programming - Nov 22, 2014

Code
if (textBox1.Text.Contains("Troll"))
{
   //Do Something
}



* - Aristocles - Nov 22, 2014

If TextBox1.Text.Contains("Troll") Then
'do things here
End If


* - Programming - Nov 22, 2014

(Nov 22, 2014 08:20 PM)Nั–etzsche Wrote:  If TextBox1.Text.Contains("Troll") Then
'do things here
End If

This is in the C# section, not the VB section.

Also format your code with the [code] tags :)


* - Jack_Soff - Nov 22, 2014

(Nov 22, 2014 08:19 PM)Programming Wrote:  
Code
if (textBox1.Text.Contains("Troll"))
{
   //Do Something
}
Fuck i tried that but had it setup wrong thats why it wasnt working, thanks so much


* - Programming - Nov 22, 2014

(Nov 22, 2014 08:22 PM)Jack_Soff Wrote:  Fuck i tried that but had it setup wrong thats why it wasnt working, thanks so much

No problem, have a nice night! ๐Ÿ˜


* - Dialog - Nov 23, 2014

[Image: humcMrl.png]

Seems like the better option to me. If you don't want to use regex, but still ignore case, you can use an overload of string.IndexOf and pass it StringComparison.OrdinalIgnoreCase.


* - Doctah - Nov 23, 2014

(Nov 23, 2014 04:58 AM)Dialog Wrote:  [Image: humcMrl.png]

Seems like the better option to me. If you don't want to use regex, but still ignore case, you can use an overload of string.IndexOf and pass it StringComparison.OrdinalIgnoreCase.

This would be the better option being that it recognizes all casing and doesn't allow for words other than exactly "troll".


* - Astek - Dec 6, 2014

you could also do.

if (this.textBox1.text == "troll")
{

}


* - Eternal Darkness - Dec 6, 2014

(Nov 22, 2014 08:19 PM)Programming Wrote:  
Code
if (textBox1.Text.Contains("Troll"))
{
   //Do Something
}

Smarter (Removes case sensitivity):
Code
if (textBox1.Text.ToLower().Contains("troll")) {
   //Do Something
}
Its a simple way of removing case sensitivity. There are other means to do so, this is just an example... >.>


* - Astek - Dec 6, 2014

ok, maybe someone on this thread can help me, im making a small program which is just a textbox takes commands theres a pic https://i.gyazo.com/0057fa3c88aabf40da62937a6597aa5f.png and i want it to spit out an error when you type in something thats not a command, this is pretty much how i tryed to do it but it splits out the error as soon as you type something in, is there anyone for it to wait a few secounds?

if (TextBox1.Text.Contains("function"))
{
// function
}
if (TextBox1.Text.Contains("function1"))
{
// function1
}
else
{
MessegeBox.Show("this isnt a command");
}


* - Fafaffy - Dec 6, 2014

PHP Code

<?php 
List<String> YouFucktard = new List<String>() { "faggot", "op", "anonymous", "69" };

if(
YouFucktard.contains(TextBox1.ToLower().Text))
{
    
MessageBox.Show("You just dun goofed");
} 



* - Astek - Dec 6, 2014

(Dec 6, 2014 08:09 AM)Fafaffy Wrote:  
PHP Code

<?php 
List<String> YouFucktard = new List<String>() { "friend", "op", "anonymous", "69" };

if(
YouFucktard.contains(TextBox1.ToLower().Text))
{
    
MessageBox.Show("You just dun goofed");
} 
that would be used to code multiple commands onto one function, yes?
i have coded a different function for each command and want it to tell me when im typing something that isnt a command, sorry if this doesnt make sense or is stupid to you, im new to this, thanks for replying.


* - fnatic - Dec 6, 2014

(Dec 6, 2014 10:16 AM)Astek Wrote:  that would be used to code multiple commands onto one function, yes?
i have coded a different function for each command and want it to tell me when im typing something that isnt a command, sorry if this doesnt make sense or is stupid to you, im new to this, thanks for replying.

"You just dun goofed"

๐Ÿ˜๐Ÿ˜