I don't understand the use of "split" in C#

I don't understand the use of "split" in C#

Postby Leeizazombie » 08 Dec 2013, 20:27

I'm making a command that renames the server and this is my attempt:

Code: Select all
if (message == "")
     {
         Help(p);
         return;
     }
     string[] split = message.Trim().Split(' ');
     if (message == "name")
     {
         Server.name = split[0];
     }


Clearly I'm doing something wrong with it at Server.name = split[0];
I want it to work like /server name (message)
I plan to add more controls, that's why.
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Re: I don't understand the use of "split" in C#

Postby Leeizazombie » 08 Dec 2013, 20:28

I just realised that this was off-topic, please move it to Help in coding :O
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Re: I don't understand the use of "split" in C#

Postby lucasds12 » 08 Dec 2013, 20:29

I don't think this is the appropriate place to add this thread, you may of put this in the place where you put the code you need help with. :mrgreen:
Edit: Bad Lee, don't post before I do. :L
-Lucas
There is only one thing I do in life, that's contributing here.
lucasds12
 
Posts: 334
Joined: 17 Apr 2013, 16:17
Location: In the deep caves.

Re: I don't understand the use of "split" in C#

Postby Leeizazombie » 08 Dec 2013, 20:30

lucasds12 wrote:I don't think this is the appropriate place to add this thread, you may of put this in the place where you put the code you need help with. :mrgreen:
Edit: Bad Lee, don't post before I do. :L
-Lucas


:P
Owner of:
LeeIzaZombie Freebuild and Lava Survival V2 (Shut Down and updated)
LeeIzaZombie Survival (Comming back soon)

Contact:
Skype: leeizazombie
IRC: irc.geekshed.net, #leeizazombie, #mcclassichosting
User avatar
Leeizazombie
 
Posts: 536
Joined: 10 Jun 2013, 17:45
Location: Ireland.

Re: I don't understand the use of "split" in C#

Postby lucasds12 » 08 Dec 2013, 20:35

It looks like this code hasn't been made yet, it seems like it to me, because this is not a normal code line, from what I seen.
And, one day I'll post before you! ;)
-Lucas
There is only one thing I do in life, that's contributing here.
lucasds12
 
Posts: 334
Joined: 17 Apr 2013, 16:17
Location: In the deep caves.

Re: I don't understand the use of "split" in C#

Postby Warren1001 » 09 Dec 2013, 01:46

Explain what you expect your piece of code to do?
Warren1001
 
Posts: 197
Joined: 08 Aug 2012, 03:50

Re: I don't understand the use of "split" in C#

Postby ismellike » 09 Dec 2013, 05:02

This is how split works.

message.Split(' '); splits your message by the spaces, so let's take your example: "/server name message"

/server is the command so that's not actually part of the message...

We are left with "name message"

split[0] is the first split, name.
split[1] is the second part, message.

You need to change your 2nd if statement to if(split[0] == "name"), and server.name has to equal split[1].

I'm not sure if that actually changes the server name though.
What a beast...
User avatar
ismellike
Coder
 
Posts: 731
Joined: 31 Oct 2012, 04:04
Location: Kansas

Re: I don't understand the use of "split" in C#

Postby joppiesaus » 09 Dec 2013, 16:26

ismellike wrote:This is how split works.

message.Split(' '); splits your message by the spaces, so let's take your example: "/server name message"

/server is the command so that's not actually part of the message...

We are left with "name message"

split[0] is the first split, name.
split[1] is the second part, message.

You need to change your 2nd if statement to if(split[0] == "name"), and server.name has to equal split[1].

I'm not sure if that actually changes the server name though.


What you said.

Here's some extra info of Arrays, which makes you hopefully understand more the split[0] stuff.
joppiesaus
 
Posts: 379
Joined: 20 Aug 2012, 07:28
Location: in a obsedian house, with glass in it so i can see the lava!


Return to Requests for Addon

Who is online

Users browsing this forum: No registered users and 1 guest

cron