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.
-
Yes it is possible. Search about string.Split and then ask a new precise question if you have problemsSteve– Steve2016-05-15 13:46:20 +00:00Commented May 15, 2016 at 13:46
Add a comment
|
1 Answer
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];
1 Comment
Steve
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