- Home /
Get a list to display all strings
Hello, I need a list of type string to be able to print all the characters in contains into one word.
public List<string> input;
if(Input.inputString!=null)
{
input.Add(Input.inputString);
}
So in this example everytime a string is entered it it saved to the list. Now Once I am ready I need to be able to print the strings together.
e.g. user enters the strings "bannana", "carrots" and "potatoes" into the list.
I would like to have code that prints the contents of the list i.e "bannanacarrotspotatoes"
Any ideas?
Thanks
Answer by robertbu · Feb 23, 2013 at 10:33 PM
Do you need to save all the string pieces? Most of the time inputString will be empty or only contain a single letter. That is inputString only contains the characters typed during last frame, so it will never be "bananas". You can collect the whole string more simply with:
public string input = "";
if (Input.inputString != null)
input += Input.inputString;
Then 'input' will be the whole string put together.
Ahh thought you could only add with integers, thats much simpler! Thanks!
Your answer

Follow this Question
Related Questions
A node in a childnode? 1 Answer
How do I get a list to randomly select.... 1 Answer
How to put a list of strings in a Text Unity 4.6 UI element 3 Answers
Can I create a list with an int/float and a string? C# 2 Answers
Convert String to int 1 Answer