Click here to Skip to main content
15,884,855 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi, this code is working. But here we get output in richtextbox, instead of this I want the extracted data to be in a different textbox. How can I achieve this? Thanks in advance.

C#
string content = "?$255*$50*$50*?";
string pattern = @"(\d+)";
MatchCollection mc = Regex.Matches(content, pattern);
string spacer = "";
if (mc.Count > 0)
{
  Console.WriteLine("Printing matches...");
    for (int i = 0; i < mc.Count; i++)
    {
        spacer = "";
        richTextBox1.AppendText(spacer + "Match[" + i + "]: " + mc[i].Value);
        GroupCollection gc = mc[i].Groups;
    }
}
else
{

    richTextBox1.AppendText("Pattern Not Found");

}



in richtextbox o/p
Match[0]: 255
Match[1]: 50
Match[2]: 50

but i want o/p like
textbox1 = 255
textbox2 = 50
textbox3 = 50 plz help.
Posted
Updated 23-Aug-11 0:02am
v3

1 solution

Then don't do richTextBox1.AppendText

Put it into different text box instead.
I would suggest using a string builder:
C#
StringBuilder sb = new StringBuilder();
string spacer = "";
for (int i = 0; i < mc.Count; i++)
{
      sb.Append(string.Format("{0}Match[{1}]: {2}",spacer, i, mc[i].Value));
      spacer = " ";
}
myTextBox.Text = sb.ToString();
Note that I moved the init of spacer outside your loop and changed it inside, and deleted the redundant GroupCollection - since it can't be accessed outside the loop, it is irrelevant.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900