Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I would like to find and select the first occurrence of a Text in a RichTextBox with C# and then select all the other finds of the same portion of Text. I know that's simple to do as long the index doesn't outrun the Integer Range. But what to do if it does? The functions RichTextBox.Find() and RichTextBox.Select() support only Integers. Now my Text Files are quite a bit larger between 41 KB and 150 KB. The Integer is definitely to small for finding and selecting with the inbuilt functions.
What would I do instead? Does someone have a ready function call for this?
Found nothing else than the inbuilt RichTextBox functions on my search which are only valid for files smaller and equal 32 KB. I am a novice in coding and I have no idea how I could build my own functions for finding and searching a RTB without using an Integer but a long. There seem to be no overloads for these functions :(

I currently use an int16 otherwise I get an exception of type mismatch.
I'm on Net 2 with VS 2008. At me the Integer carries only 32768 characters. I want to save the whole search string in the int16 but can store only one char so far.
What am I doing wrong? Now I changed to int32 and it seems to compile.
Posted
Updated 28-Mar-15 7:36am
v3
Comments
Sascha Lefèvre 28-Mar-15 12:00pm    
An "int" (Int32) can represent a value up to 2,147,483,647. That's more than enough for a 150 KB text :)
Richard MacCutchan 29-Mar-15 8:34am    
Please stop flooding this question with these vague comments, and then deleting them. If you have a problem then edit your question, show us the code that is failing and explain exactly what is happening and why it is incorrect.
Richard MacCutchan 29-Mar-15 13:57pm    
I have not deleted any of your posts. However, I have reported all your abusive messages.

An integer gives you a range of 0 to 2,147,483,647, which should be plenty for a 150 Kb file.
 
Share this answer
 
Comments
Richard MacCutchan 28-Mar-15 13:34pm    
Why? Integers are 32 bits wide, use them.
Maciej Los 28-Mar-15 14:07pm    
+5
BillWoodruff 29-Mar-15 2:43am    
+5
OriginalGriff 29-Mar-15 6:05am    
Probably because your int16 value got too big, and went negative.
So when you cast it to an int32, that was a negative number as well...
Um.
int is a 32bit value, with a range of -2147483648 to 2147483647
If your rich text exceeds 2GB in size, then you have a problem - and that's that the user will will never read it all, for starters...
 
Share this answer
 
Comments
OriginalGriff 28-Mar-15 13:20pm    
Why are you using an int16? All that will happen is that the system will use an implicit cast to convert it to an int32 - all int variables in C# are 32 bit unless you explicitly use short or int16.
BillWoodruff 29-Mar-15 2:43am    
+5

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