How do I add multiple contact number from Ritchtextbox to Datagridview?

50 pts.
Tags:
.NET
C
If i have add the number of contacts numbers into grid view. For example, I have 10 numbers, add the numbers in rich text box and transfer grid view.
It displays all numbers in single row. But I have all numbers display row by row in grid view. So, how do I separate the value from text box and add the all values in gridview?
Please give some example code for C# winform.
Thanks&Reg
Sathya


Software/Hardware used:
.Net(C# winforms)
1

Answer Wiki

Thanks. We'll let you know when a new response is added.

How to split strings using regular expressions

The Regular Expressions Split() methods are almost similar to the String.Split() method, except that Regex.Split() method splits the string at a delimiter determined by a Regular Expression instead of a set of characters.

When using Regular Expressions you should use the following namespace in your project

using System.Text.RegularExpressions;

string str = txtAddNumber.Text;

string[] result = Regex.Split(str, “\n\\s*”);            

for (int i = 0; i < result.Length; i++)

               
{

MessageBox.Show(result[i]);
}

Output:

one
two
three
four

Discuss This Question: 3  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • Subhendu Sen
    Is this a real time scenario. This is so old method, and this method used when FoxPRO / VB6 in the market. You don't really have reliable access to it from your code. And also this is not a practical purpose. Try to use SQL server / Oracle for the same purpose.
    140,720 pointsBadges:
    report
  • ToddN2000
    This sounds like a homework question.
    In your textbox, how are the numbers separated? comma, space or even tab?
    1,4,6,9,3   
    1 4 6 9 3 
    1 4 6 9 3
    You can use that as your delimiter and substring out the individual number values. Post your code and we can help you fix any issues you have.
    134,495 pointsBadges:
    report
  • SathyaSri
    I got an answer, we can split a string by multi character delimiter using RegularExpressions.

    My source code

           string str = txtAddNumber.Text;

           string[] result = Regex.Split(str, "\n\\s*");

           for (int i = 0; i < result.Length; i++)

                    {

                        string GetText = (result[i]);

                        TextValue.Add(GetText);

                    }

          Thanks you..


50 pointsBadges:
report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: