Hack Forums
[C#] Switch Case command and argument? [!(command) (argument)] - 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#] Switch Case command and argument? [!(command) (argument)] (/showthread.php?tid=4168363)

Pages: Pages 1 2


Switch Case command and argument? [!(command) (argument)] - OG Gangsta - Apr 12, 2014

I am using a switch statement to grab commands from elsewhere, and I was wondering about something. If I wanted a command like '!blahblah [url]', how would I make a case for that?

This is what I really need, but it doesnt work
Code
case "blahblah" + cmd:
    break;



* - Cornflower Blue இڿڰۣ-ڰۣ— - Apr 12, 2014

http://msdn.microsoft.com/en-us/library/ms228388.aspx


* - OG Gangsta - Apr 12, 2014

(Apr 12, 2014 04:19 PM)lhendrey4.5 Wrote:  http://msdn.microsoft.com/en-us/library/ms228388.aspx

I don't see how that helps, could you explain more?

For example, If I wanted to make a command that resolved IP's via Skype, the user typing to command would have to input a skype name, which can be anything. Like, '!resolve boneritus'. How can I collect this comand with a case (after removing the '!' of course)


* - Kain_12 - Apr 12, 2014

Use strcmp? Compare strings? You need to include cstring library.


* - CodeJack - Apr 12, 2014

I can't remember off the top of my head, but can't you make a temp string beforehand.

String str = "blahblahblah" + cmd;

switch(str){
case peniscake:
break;
}


* - Cornflower Blue இڿڰۣ-ڰۣ— - Apr 12, 2014

(Apr 12, 2014 04:23 PM)OG Gangsta Wrote:  I don't see how that helps, could you explain more?

For example, If I wanted to make a command that resolved IP's via Skype, the user typing to command would have to input a skype name, which can be anything. Like, '!resolve boneritus'. How can I collect this comand with a case (after removing the '!' of course)

There is a whole example on that link on what you need to do.
Think about it, you want to SPLIT up a string into different parts.

Edit: Nevermind, read OP wrong. Just do this: string joined = "Test" + "ing";


* - Geekie - Apr 12, 2014

PHP Code

<?php 
string
[] str = "blah|" + cmd;
swtich(str[0])
[
case 
cmd:
break;
} 

Just use the | as a delimiter


* - OG Gangsta - Apr 12, 2014

(Apr 12, 2014 05:50 PM)PROG Wrote:  
PHP Code

<?php 
string
[] str = "blah|" + cmd;
swtich(str[0])
[
case 
cmd:
break;
} 

Just use the | as a delimiter

That might've worked, but my cmd is a normal string, not a string[]


* - Dongahh - Apr 12, 2014

You need to split the string.

Note: Not exactly what you want I don't think but could possibly help.
Code
string str = "blah|" + cmd;
switch (str.Split('|')[0])
{
    case "blah":
    string cmd = str.Split('|')[1];
    break;
}

Try that OP. Also so I can help better, what is this for?


* - OG Gangsta - Apr 12, 2014

(Apr 12, 2014 07:11 PM)Dongahh Wrote:  You need to split the string.

Note: Not exactly what you want I don't think but could possibly help.
Code
string str = "blah|" + cmd;
switch (str.Split('|')[0])
{
    case "blah":
    string cmd = str.Split('|')[1];
    break;
}

Try that OP. Also so I can help better, what is this for?
I am making a private botnet for me and a few buddies, and I am trying to add a ddos command.

As in '!ddos 85.291.384.822'


(Apr 12, 2014 07:11 PM)Dongahh Wrote:  You need to split the string.

Note: Not exactly what you want I don't think but could possibly help.
Code
string str = "blah|" + cmd;
switch (str.Split('|')[0])
{
    case "blah":
    string cmd = str.Split('|')[1];
    break;
}

Try that OP. Also so I can help better, what is this for?

It didn't work :( One day.... One day.


* - NETExplorer - Apr 12, 2014

Case values must be constant. In other words you can't have
switch(myString)
{
case "Hello" + otherString:
break;
}


* - OG Gangsta - Apr 12, 2014

(Apr 12, 2014 09:31 PM)PatPositron Wrote:  Case values must be constant. In other words you can't have
switch(myString)
{
case "Hello" + otherString:
break;
}

I realize that, I'm looking for an alternative


* - Dongahh - Apr 13, 2014

(Apr 12, 2014 07:16 PM)OG Gangsta Wrote:  I am making a private botnet for me and a few buddies, and I am trying to add a ddos command.

As in '!ddos 85.291.384.822'



It didn't work :( One day.... One day.

So your commands will be formatted like !(command) (argument)?

If so then here's an example;
Code
string str = "!ddos 85.291.384.822";
switch (str.Split('!')[1])
{
    case "ddos":
      string ip = str.Split(' ')[1];
      break;

}

Not the cleanest code nor would I usually do it like that but don't have access to Visual Studio.


* - OG Gangsta - Apr 13, 2014

(Apr 13, 2014 12:29 AM)Dongahh Wrote:  So your commands will be formatted like !(command) (argument)?

If so then here's an example;
Code
string str = "!ddos 85.291.384.822";
switch (str.Split('!')[1])
{
    case "ddos":
      string ip = str.Split(' ')[1];
      break;

}

Not the cleanest code nor would I usually do it like that but don't have access to Visual Studio.
That is good, but that will only allow the user to boot that one IP. Im trying to make it so you can input any IP, and it will still go into the case.


* - frontenhack - Apr 13, 2014

(Apr 13, 2014 12:47 AM)OG Gangsta Wrote:  That is good, but that will only allow the user to boot that one IP. Im trying to make it so you can input any IP, and it will still go into the case.

WTF are you talking about?,
You can code a priv8 botnet and you don't know how to concat strings. 😧

I would suggest you to learn c# before doing anything...