using Split

  • Thread starter Thread starter Mike P
  • Start date Start date
M

Mike P

I am using Split to split get a number of items from a multi line text
box. But I need to be able to get the number of elements within the
text box (e.g. if the text box has 2,4,8 in it, I want to be able to
count that this text box has 3 elements entered into it). My code is
below :

for (int p=0; p < dgNational.Items.Count; p++)
{
strQuantity =
((TextBox)dgNational.Items[p].FindControl("txtAccount")).Text +"\r\n";

string strDelimiter = "/r/n";
char [] Delimiter = strDelimiter.ToCharArray();

string [] strSplit = null;

for (int x=0; x <= 100; x++)
{
strSplit = strQuantity.Split(Delimiter, x);
}


if (strSplit.Length != dgNational.Items.Count)
{
lblErrorNational.Text = "Invalid number of accounts entered";
return;
}
}


Any help would be much appreciated.


Cheers,

Mike


*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
 
Mike,

You can use Split again on each of the lines that are returned. Then,
all you have to do is sum the total of the Length properties of the returned
arrays, and that should give you the number you need.

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top