1

I'm having trouble finding this online but basically I want to know if its possible to use Console.ReadLine (); and write something like "dog cat cow" and store "dog" in a string variable, "cat" in another one, etc.

1
  • Yes it is possible. Search about string.Split and then ask a new precise question if you have problems Commented May 15, 2016 at 13:46

1 Answer 1

2

This is how I did it, it worked fine but is this the proper way of doing it?

        string s = "dog cat cow";
        string[] words = s.Split(' ');

        string i = words [0];
        string i1 = words [1];
        string i2 = words [2];
Sign up to request clarification or add additional context in comments.

1 Comment

Yes that's a way to do it, however there is no apparent need to create three different variables. You could keep everything in the array and reference the appropriate index when you need it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.