Lets assume you have a string:
- string str = "Some Text";
And you have a control, for example:
- TextBox textBox1 = new TextBox();
What do you want to do, exactly?
Do you want to name your control using your string? If so, first make sure it doesn't contain any invalid characters. Which are those? I'm not sure at the moment, but the space is certainly not allowed. SO you'll have to remove it, and then assign it to your control's name, for example like that:
- textBox1.Name = str.Replace(" ","");
Then, as GaryTexmo said, you can look it up using, e.g. Find, or IndexOfKey method
Find:
- Controls [] ctab = yourContainer.Controls.Find(str.Replace(" ",""));
-
if(ctab.Count!=0)
-
Control found = ctad[0];
where yourContainer is your form or panel that the textBox1 is child of.
http://msdn.microsoft.com/en-us/libr...tion.find.aspx
Using IndexOfKey:
- int idx = yourContainer.Controls.IndexOfKey(str.Replace(" ",""));
-
if(idx!=-1)
-
Control found = yourContainer.Controls[idx];
http://msdn.microsoft.com/en-us/libr...ndexofkey.aspx
If you just want to show your string in a TextBox, assign it to your TextBox Text field: