0

I have a user input which has only 3 words so to say.

Example of user input:

"/login user pass", "/register user pass".

These values are being stored in a string all together (string command), how can I obtain the values of 'user' and 'pass' given the fact that they are separated by an empty space?

Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
Firesky
  • 17
  • 4
  • 1
    Tip: You could rephrase your question as "how do i split a string by the space character". There are _many_ questions on here already that strive to answer that. – ProgrammingLlama May 07 '18 at 11:03
  • 2
    Possible duplicate of [How do I split a string by a multi-character delimiter in C#?](https://stackoverflow.com/questions/1126915/how-do-i-split-a-string-by-a-multi-character-delimiter-in-c) – FCin May 07 '18 at 11:06
  • 1
    Not sure if you are talking about command line arguments if so look here https://stackoverflow.com/questions/491595/best-way-to-parse-command-line-arguments-in-c – Rand Random May 07 '18 at 11:07
  • This question is too broad. What are you trying to do? If you want to create a command-line parser there are multiple NuGet packages. The `args` parameter of your `Main()` function *already* splits the command line so you don't need to do it yourself. If there's no such parameter, add it and .NET will fill it. – Panagiotis Kanavos May 07 '18 at 11:12

2 Answers2

0

Just use the String.Split() method:

string command = "/login user pass";
var result = command.Split();
string user = result[1];//"user"
string pass = result[2];//"pass"
Slaven Tojić
  • 2,945
  • 2
  • 14
  • 33
0

if this input is in excel then you can use "text to columns" option. for that you first go to DATA and then click on "text to columns" button. click on fixed width and click next.