Looking for new line symbol

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All,
I have textbox and i have to count new line symbol (char 13). But when i tried to do this

int neco = textBox.Text.IndexOf((char)13, 0,textBox5.SelectionStart);

I received error, only if the symbol (char 13) is in the string. Else everything is ok. I don't know why..........
 
Systemspecialist said:
I have textbox and i have to count new line symbol (char 13). But
when i tried to do this

int neco = textBox.Text.IndexOf((char)13, 0,textBox5.SelectionStart);

I received error, only if the symbol (char 13) is in the string. Else
everything is ok. I don't know why..........

As always, it would help if you'd tell us what the error is.
 
Systemspecialist said:
I received this error:

ArgumentOutOfRangeException

With no more message than that? Usually it specifies which argument is
out of range.

Just looking at your code again, you're using textBox5.SelectionStart
as the first index to look at - but in a different text box. Perhaps
that's the problem?

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.
 
No , I received only this message.

int pomocny = 0, neco = 0;
while(pomocny != -1)
{
pomocny = textBox.Text.IndexOf((char)13,pomocny,textBox.SelectionStart);
neco++;
}

In parameter neco I count (char)13 in string. In my 1st post I made error. I use only textBox, no textBox5, so there is not problem . I tried to make my own function, where i checked every char of the string, it's work fine, but very slowly.
 
Systemspecialist said:
No , I received only this message.

int pomocny = 0, neco = 0;
while(pomocny != -1)
{
pomocny = textBox.Text.IndexOf((char)13,pomocny,textBox.SelectionStart);
neco++;
}

In parameter neco I count (char)13 in string. In my 1st post I made
error. I use only textBox, no textBox5, so there is not problem . I
tried to make my own function, where i checked every char of the
string, it's work fine, but very slowly.

The third parameter of IndexOf is the number of characters to examine,
not the index of the last character to examine. You should change your
code to make the last parameter textBox.SelectionStart-pomocny, I
suspect.
 
Back
Top