0
votes

The result that I'm seeking at the moment is to split textBox1.Text into as many textboxes as possible , as long as the splitting sign exist ('+' or '#' for example)

So each new textbox should only have the word between the two signs example :

textBox1.text = "one+two+three"; then textBox2.text = "one"; textBox3.text = "two"; textBox3.text = "three";

The following two examples achieve 90% of what I need , but I still can't figure out how to put the values each in a separate textBox.text :

string str = "one\n   \ntwo\n   \nthree\n   \n   \nfour";
string[] result = Regex.Split(str, "\n\\s*");
for (int i = 0; i < result.Length; i++)
    MessageBox.Show(result[i]);

and

string input = "one)(two)(three)(four)(five";
string[] result = input.Split(new string[] { ")(" }, StringSplitOptions.None);
foreach (string s in result)
    MessageBox.Show(s);
2
Is this a windows app (WPF or WinForms) or a web app (MVC or WebForms)? - epotter
@epotter it's Windows app (WinForms) - Sherif Kamel

2 Answers

0
votes

You need to split the result (as you already did) and then for each result dynamically create a textbox and set its text. Your code should look like this:

int i = 0;
foreach (var item in result)
{
    var textBox = new TextBox();
    textBox.Location = new System.Drawing.Point(0,i++*25);
    textBox.Text = item;
    this.Controls.Add(textBox);
}

The integer i is used to make sure that each textbox appears at a different location and not on top of each other.

0
votes

Something like this

string[] result = textBox1.text.Split('+');

foreach (int i=0;i<result.Lenght;i++)
{
TextBox box = new TextBox();
box.Name = "textBox"+i;
box.Text = result[i];
somewhere.Add(box);
}