|
You could use the lower-case versions of the search string and the text to locate the match (or matches); then remove whatever exists at the match position (you know position and length), and then insert the new text with its original casing.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
|
please read my reply again: you search using the lower-case versions, only to find the location.
you modify using the actual text, not the lower-case one (the positions are the same for both!)
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
this is what i have done so far... but with the same result. The text in richTextBox1 is changing to lower and I dont see from where.
int posTxt = 0;
private void button2_Click(object sender, EventArgs e)
{
string searchText = textBox2.Text.ToLower();
string alltxt = richTextBox1.Text.ToLower();
RichTextBox rtb = new RichTextBox(); rtb = richTextBox1;
if (alltxt.Contains(searchText))
{
rtb.Text = alltxt;
while (posTxt != -1)
{
posTxt = rtb.Find(searchText, posTxt, RichTextBoxFinds.MatchCase);
if (rtb.SelectedText == searchText)
{
richTextBox1.SelectionLength = searchText.Length;
richTextBox1.SelectionColor = Color.Red;
}
posTxt = rtb.Find(searchText, posTxt + 1, RichTextBoxFinds.MatchCase);
}
}
posTxt = 0;
}
|
|
|
|
|
_q12_ wrote: The text in richTextBox1 is changing to lower and I dont see from where.
_q12_ wrote: string alltxt = richTextBox1.Text.ToLower();
_q12_ wrote: rtb.Text = alltxt;
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
yes... but...
only rtb.Text = richTextBox1.Text; not inverse.
RichTextBox rtb = new RichTextBox(); rtb = richTextBox1;
meaning:
richTextBox1.Text is not equal with rtb.Text.
anyway... its not about the new rtb.
|
|
|
|
|
_q12_ wrote:
rtb = richTextBox1;
WRONG!
you have copied the reference, so both rtb and richTextBox1 point to the same object.
the new RichTextBox you also created is dead right away, it is never used (it also is not needed!).
BTW: Eric already told you all that.
I suggest you choose, buy and thoroughly study an introductory book on C#.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
As told earlier by Luc, rtb and richtextBox1 refer(point to the same object).
Think of it this way: rtb and richtextbox1 are just some names that help you deal the the real thing.
A guick fix for what you are trying to do with this line of code would be:
RichTextBox rtb = new RichTextBox(); rtb.Text = richTextBox1.Text;
Now rtb does not point to the same object but it just copied the text from richtexbox1.
Clearer than that I don't know how to explain.
All the best,
Dan
modified on Friday, May 27, 2011 3:35 PM
|
|
|
|
|
As Luc has already suggested:
Do not assign alltxt to rtb.Text nor richTextBox1.Text; Actually, remove rtb variable, you don't need it;
Use alltxt.IndexOf method instead of rtb.Find method to search for the text you want. The indexes will be the same.
Use these indexes to make the changes on your rich text box control.
The lines:
RichTextBox rtb = new RichTextBox(); rtb = richTextBox1;
are useless becouse RichTextBox is a reference type, so your local rtb variable and your richTextBox1 will both be pointing to the same object.
|
|
|
|
|
in some desperation I was using "RichTextBox rtb " variant, copying its locations to the real one...
But I managed to find the solution after all.
Thanks!
|
|
|
|
|
richTextBox1.Text = alltxt;
Why are you doing that? You are explicitly setting the text to the lower case version in that line. The only difference between the text property and alltxt is that you ran ToLower on alltxt!
Also, RichTextBox.Find, if you want to use it, already searches case-insensitively by default. Did you read the documentation for RichTextBoxFinds[^]? Passing RichTextBoxFinds.None will cause the search to be case-insensitive – you explicitly asked for a case sensitive one, for some reason.
|
|
|
|
|
Problems Solved:
Sincerely, I did changed RichTextBoxFinds.None before posting here on forum, but for some strange reason, it did not work back then... Now it works fine.
I have another problem...see it beneath code.
Here is the functional code:
int posTxt = 0; string tempText = "";
private void button2_Click(object sender, EventArgs e)
{
richTextBox1.Text = tempText;
string searchText = textBox2.Text.ToLower();
string alltxt = richTextBox1.Text.ToLower();
if (alltxt.Contains(searchText))
{
if (posTxt <= 0)
{
richTextBox1.Text = richTextBox1.Text.Insert(0, " ");
posTxt = 1;
}
while (posTxt > 0)
{
posTxt = richTextBox1.Find(searchText, posTxt, RichTextBoxFinds.None);
if (richTextBox1.SelectedText.ToLower() == searchText)
{
richTextBox1.SelectionLength = searchText.Length;
richTextBox1.SelectionColor = Color.Red;
}
posTxt = richTextBox1.Find(searchText, posTxt + 1, RichTextBoxFinds.None);
}
}
posTxt = 0;
}
But i have a little problem now...
If I load a *.rtf file with formatting text and search a word in that richTextBox1 that show that file, the text is re-formatting, loosing its original format.
How to maintain its original format, and select as usual(with red marking)?
|
|
|
|
|
I found the following sp on this website, when I run it by right clicking on the procedure in the DB using the command "Execute Stored Procedure" it works fine. However, when I run the sp from C# I get the following error:
//err.Message = "Microsoft SQL Native Client:
//CONFIG statement cannot be used inside a user transaction.\\42000 = 574;
//Microsoft SQL Native Client: Configuration option 'show advanced options'
//changed from 0 to 1. Run the RECONFIGURE statement to install.\\01000 = 15457"
ALTER PROCEDURE [dbo].[sp_Database_ResetMemory]
AS
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE WITH OVERRIDE;
EXEC sp_configure 'max server memory (MB)';
EXEC sp_configure 'max server memory (MB)', 512;
RECONFIGURE WITH OVERRIDE;
EXEC sp_configure 'max server memory (MB)';
WAITFOR DELAY '00:00:15';
EXEC sp_configure 'max server memory (MB)', 2147483647;
RECONFIGURE WITH OVERRIDE;
EXEC sp_configure 'max server memory (MB)';
EXEC sp_configure 'show advanced options', 0;
RECONFIGURE WITH OVERRIDE;
Can anyone tell me what the problem is.
Thanks in advance,
Michael
|
|
|
|
|
This may get a faster answer if posted to the Database forum, there does not seem to be a C# issue here.
The best things in life are not things.
|
|
|
|
|
Is there a way to somehow disable or remove the ProductVersion component of some of the "Application" object properties such as the "UserAppDataRegistry" property?
Application.UserAppDataRegistry =
CurrentUser\Software\CompanyName\ProductName\ProductVersion
|
|
|
|
|
Ho do you test to ensure that the first character/digit in a string is a positve number? ie. 1 to 9, instead of -1 to -9.
Everything makes sense in someone's mind
|
|
|
|
|
Hi,
^\d+$
should match "begin-of string, one-or-more-digits, end-of-string"
Did you loose all documentation on the Regex class? such as this[^].
BTW: we also have a regex forum.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
I don't want to be picky, but OP only wanted a digit in the first place. Nothing was said which demanded anything specific for the rest of the string.
Anyways my 5+
|
|
|
|
|
I was aware of that, and that is exactly why I sort of explained the pattern. He could use three characters from it and get any string that starts with a digit.
BTW: it also applies to your approach, at least the one you posted originally.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
modified on Thursday, May 26, 2011 6:57 PM
|
|
|
|
|
If he is just checking for a positive first digit, regex is a horrible, expensive solution anyways... just check '0' <> '9', not like they are going to invent new digits any time soon.
|
|
|
|
|
I agree. And that is one reason why I seldom use regex, the other is readability isn't great.
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|
|
I definitely use it when I need to scrub more complex input, but for a single digit? waaay overkill... thats like using a sledge hammer (no pun intended) to hang up a picture.
|
|
|
|
|
I use them for matching or manipulating strings in non-trivial manners, for example parsing a command line into parameters or extracting information out of HTML source. They may not be particularly readable but they're better than 10 lines of code for the same job. That said, I absolutely agree that a regex for this is ridiculous.
|
|
|
|
|
^[0-9].*$ should do it!
Cheers!
|
|
|
|
|
I don't want to be picky, but when the string contains a \n it will never match. Why didn't you stop at
^[0-9]
?
Luc Pattyn [My Articles] Nil Volentibus Arduum
The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Please use <PRE> tags for code snippets, they improve readability. CP Vanity has been updated to V2.3
|
|
|
|