|
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
|
|
|
|
|
Correct!
But to be honest, I agree with Sledgehammer on this: Regex for checking one character is overkill!
Cheers!
|
|
|
|
|
As others have pointed out, regex is massive overkill for this. Try
if(s.Length == 0) return neither;
else if(s[0] == '-') return negative;
else if(s[0] >= '0' && s[0] <= '9') return positive;
else return non-numeric;
Return values are probably an enum or conditions on other bits of code to run. This relies on the numbers being in the character set in order and contiguously, which is true in every encoding I'm aware of.
|
|
|
|
|
I need to scrape a website. The information is stored in SQL and is sent in response to a javascript on the web page. I can use the WebResponse to download the original page source and formulate the necessary java script. Is there a way to execute the javascript using System.Web objects? I tried using automation to create an instance of IE but the new version of IE (9) creates response windows which require manual intervention.
I would like to do something like
<pre>
write(javascript:window.open(document.getElementById('ReportViewerControl').ClientController.m_exportUrlBase, '_self'))
</pre>
Thx
Mark Jackson
|
|
|
|
|
If I understand this right, you want to take a page source and execute JS within it to extract data?
Website scraping is a specific thing for each site, whatever you do, so I recommend that you instead parse the JS (it's almost certainly automatically generated and therefore easy to automatically decompose) to get the data. A regex ought to be able to do that for you. Executing arbitrary JavaScript could produce surprising or even malicious results.
Also, you should check that automated scraping doesn't violate the terms of use of the website, particularly if the content you are scraping is not visible without an account.
|
|
|
|
|
I have 3 separate lists of objects, all containing the same properties:
List<SalesTeamNorth> teamNorth;
List<SalesTeamSouth> teamSouth;
List<SalesTeamEast> teamEast;
Is there a way to merge these 3 lists into a single list (i.e. "List<AllSalesReps> allReps")? I was able to figure out how to merge 3 lists of the same object but not 3 lists of different objects.
For most of my application, it's beneficial to keep these 3 objects separate, however there's one part in which having them merged into a single list object will save me from using lots of repetitive code.
Thanks.
|
|
|
|
|
Do they all share something like a base class, or even better, an interface? If they do, just use that as your type - the horrible alternative is to maintain it as a List of objects which, quite frankly, is no better than maintaining an ArrayList.
|
|
|
|
|
Even when your SalesTeamXyz classes would inherit from a common SalesTeam class, you wouldn't be able to simply cast a List<SalesTeamNorth> to a List<SalesTeam>, so the three lists have no common ancestor. [fixed angular brackets here].
Now do you really want those three classes? and even if you do, do you need the highly specialized lists? it would probably make more sense to have compatible lists, like so:
List<SalesTeam> teamNorth;
List<SalesTeam> teamSouth;
List<SalesTeam> teamEast;
while you still can store more specialized teams in them (with a risk of making some mistakes).
Here is a complete example:
class SalesTeam {
public string name;
}
class SalesTeamNorth : SalesTeam {
public SalesTeamNorth(int v) { name="N"+v; }
}
class SalesTeamSouth : SalesTeam {
public SalesTeamSouth(int v) { name="S"+v; }
}
public override void Test(int arg) {
List<SalesTeam> teamsNorth=new List<SalesTeam>();
for(int i=0; i<3; i++) teamsNorth.Add(new SalesTeamNorth(i));
List<SalesTeam> teamsSouth=new List<SalesTeam>();
for (int i=0; i<3; i++) teamsSouth.Add(new SalesTeamSouth(i));
foreach (List<SalesTeam> teams in new List<List<SalesTeam>>(){ teamsNorth, teamsSouth }) {
foreach (SalesTeam team in teams) {
log(team.name);
}
}
}
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 12:43 PM
|
|
|
|