|
it seems from your second method you need to parse your string from string builder to lines like what you read from the Stream Am I right?
if it is what you need you can do with Split method from string instances like
string s = "hello \r\n how are you? \r\n";
string[] sArr = s.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
StringCollection col = new StringCollection();
col.AddRange(sArr);
it was the easiest way with least code change
however your methods are not efficient you can add your string to StringCollection instance instead of writing sb.Append("/r/n")
hope the post would be useful
good luck
|
|
|
|
|
You are correct in your assumption.
I am not following what you are suggesting.
I am not asking for a rewrite of the code, maybe a snipit within the sample I sent as I tend to understand it better from a practical example(what I am working on).
Hessam Jalali wrote: string s = "hello \r\n how are you? \r\n";string[] sArr = s.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);StringCollection col = new StringCollection();col.AddRange(sArr);
Hessam Jalali wrote: however your methods are not efficient you can add your string to StringCollection instance instead of writing sb.Append("/r/n")
Thanks,
Brian
|
|
|
|
|
solutionsville wrote: or am I out of my mind.
Nothing here leads me to that conclusion.
If I understand correctly what you mean by incorporating the two routines, you might be able to do something like this.
StringCollection ReadFileIntoStringCollection()
{
const int MaxBytes = 65536;
StreamReader sr = new StreamReader ( chosenFile );
StringCollection result = new StringCollection();
int nBytesRead = 0;
string nextLine;
while ( ( nextLine = sr.ReadLine() ) != null )
{
nBytesRead += nextLine.Length;
if ( nBytesRead > MaxBytes )
break;
result.Add ( nextLine );
}
sr.Close();
return result;
}
When I say "guts" I mean leave out the first few lines, start with the declaration of sb and go through the end of the while loop. Once you do that there may be some compilation errors or warnings to fix, but I think it should work. Or can be made to work.
Hope that's more or less what you had in mind.
BDF
|
|
|
|
|
Big Daddy, you are the man!
This have been driving me nuts for about a week. This is what it looks like combined and working.
--------------
So if I want to add this piece to the same method above, where would I put this?
private void findSequenceNumbers()
{
toolStripStatusLabel.Visible = toolStripProgressBar.Visible = true;
toolStripProgressBar.Value = 0;
int lineNum = 0;
bool startingNewLine = true;
FontStyle style = FontStyle.Bold;
string[] lines = rtbDoc.Lines;
string text = rtbDoc.Text;
toolStripProgressBar.Maximum = text.Length;
for (int i = 0; i < text.Length; i++)
{
if (startingNewLine)
{
if ((lines[lineNum].Contains("ARES_EINDICATION")) || (lines[lineNum].Contains("ARES_INDICATION")))
{
i += 169;
rtbDoc.Select(i, 2);
rtbDoc.SelectionFont = new Font(rtbDoc.SelectionFont, rtbDoc.SelectionFont.Style ^ style);
rtbDoc.SelectionColor = Color.DarkBlue;
}
else if (lines[lineNum].Contains("]CODELINE_INDICATION_MSG"))
{
i += 160;
rtbDoc.Select(i, 2);
rtbDoc.SelectionFont = new Font(rtbDoc.SelectionFont, rtbDoc.SelectionFont.Style ^ style);
rtbDoc.SelectionColor = Color.DarkBlue;
}
else
{
i += lines[lineNum].Length - 1;
}
startingNewLine = false;
Application.DoEvents();
}
if (text[i] == '\n')
{
startingNewLine = true;
lineNum++;
}
toolStripProgressBar.Value = i;
}
toolStripStatusLabel.Visible = toolStripProgressBar.Visible = false;
rtbDoc.Select(0, 0);
rtbDoc.ScrollToCaret();
}
Thanks and have a good weekend!
-- modified at 15:53 Saturday 25th August, 2007
|
|
|
|
|
Hi Brian,
I had a good weekend, hope you did too.
That's going to be a bit more involved. There are two approaches that I see, no doubt there are others as well.
First approach is to get the data from the file into memory using ReadFileIntoStringCollection() which now also does the work formerly done in LayoutInput() . Now the data is in a StringCollection object, from there it needs to go into the RichTextBox control. I don't know the best way to do this, it will take a little bit of experimentation. It might be as simple as rtbDoc.Text = result.ToString(); but I'm not sure that will work. You might have to iterate through result appending each string element onto rtbDoc.Lines or something like that. Once that data is in the RichTextBox control you can just call findSequenceNumbers() . This would offer the advantage of still being able to Select() a portion of the text and change the SelectionFont and SelectionColor . A big disadvantage might be the effort of getting the data into the RichTextBox control and the possible time used by findSequenceNumbers() .
Second approach involves more hacking up of the findSequenceNumbers() function and copying it into ReadFileIntoStringCollection() . To do this, instead of searching for your targets in lines[lineNum] you'll search in an element of result . Probably you can still use the [] array notation, seems to work with most Collection objects. But now you can't just set the SelectionFont and SelectionColor properties because we have just a plain old string, not the contents of a RichTextBox control. Instead you'll need to insert the raw rtf formatting sequences. Also you'll need to put some other rtf stuff into the beginning elements ofresult as well as some ending stuff once the file reading is done.
If you use the second approach, we find ourselves back to the problem of getting the StringCollection object into the RichTextBox control. Except now we're hoping that rtbDoc.Rtf = result.ToString(); is the silver bullet. You might consider putting in a temporary statement like
string temp = result.ToString();
in the while loop when reading the file. Just so you can see in the debugger what is going to returned by calling ToString() on a StringCollection object. Another thing to beware of is that you proably need to append "\r\n" to the end of each string element of result in order to see the line breaks in the RichTextBox control.
I would probably do the searching of each line just after it's been read and preprocessed. I haven't thought too much about handling the ProgessBar etc., but I'd worry about that after the other stuff gets worked out.
Hope this helps a little.
BDF
|
|
|
|
|
Hey BDF, yes I had a great weekend, time on the Harley, etc...
I had the same thought you did, and tried it. I didn't get any more speed performance from the routine doing it either way.
What did cut the time down on the load to RTB was to disable the RTB control until the routine is complete. It went from 3 1/2 minutes to about 20 seconds for a 8MB file.
I am gonna move on.
You have provided me great insight as to what I was missing.
Thank you very much for you help!
V/R
Brian
|
|
|
|
|
solutionsville wrote: disable the RTB control until the routine is complete
Good idea. Wish I'd thought of that!
I suppose the code was chugging along putting in lots of the rtf commands and each time the control had to redisplay itself. Only having to do that one time would account for the big time difference.
Good luck with your project!
BDF
|
|
|
|
|
plz can someone help me to get a FREE version of infragistics NetAdbantage for .Net from onother source of "www.infragistics.com" ?
|
|
|
|
|
well...I know that there is an evaluation license for NetAdvantage, but I haven't ever had to deal with it because I have access to an Enterprise license. ...Is there any specific reason why you don't want to get the eval versions from infragistics.com?
"I need build Skynet. Plz send code"
|
|
|
|
|
I presume because the eval versions time out after X days or are crippled in some way.
--
You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer
|
|
|
|
|
I want that after the last no. I should get a full stop instead of a comma.Pl correct my code.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Ch11Ex03yield
{
public class Primes
{
private long min;
public long max;
public Primes()
: this(2, 100)
{
}
public Primes(long i, long j)
{
if (i < 2)
{
min = 2;
}
min = i;
max = j;
}
public IEnumerator GetEnumerator()
{
for (long possiblePrime = min; possiblePrime <= max; possiblePrime++)
{
bool isPrime = true;
for (long possibleFactor = 2; possibleFactor <=
(long)Math.Floor(Math.Sqrt(possiblePrime)); possibleFactor++)
{
long remainderAfterDivision = possiblePrime % possibleFactor;
if (remainderAfterDivision == 0)
{
isPrime = false;
break;
}
}
if (isPrime)
{
yield return possiblePrime;
}
}
}
}
class Program
{
static void Main(string[] args)
{
Primes myPrimes = new Primes(2,1000);
foreach (long i in myPrimes)
Console.Write("{0}{1} ",i,
(i==myPrimes.max )?".":",");
Console.ReadKey();
}
}
}
|
|
|
|
|
System.Console.Write ( "\b." ) ;
|
|
|
|
|
...or you could just do that
"I need build Skynet. Plz send code"
|
|
|
|
|
for One...you're gonna wanna repost that code placed inside pre tags. ...That code is not illegible as is, but it's just an eyesore.
For two...well, format your code first
btw...you wouldn't happen to know how to build Skynet would you?
"I need build Skynet. Plz send code"
|
|
|
|
|
Did you read the reponses from when you posted this earlier?
|
|
|
|
|
Alaric_ wrote: you wouldn't happen to know how to build Skynet would you?
Hah! If you think we're going to do your homework for you, sonny jim, you've got another thing coming!
I do have a few pointers for you, though:
public class BABaracus : HardAsNails<br />
{<br />
<br />
private murdoch = new murdoch();<br />
private hannibal = new hannibal();<br />
<br />
public BABaracus()<br />
{<br />
<br />
if(murdoch.IsFool)<br />
{<br />
this.StartPitying();<br />
}<br />
else<br />
{<br />
this.DrinkMilkContaminatedWithSleepingPills();<br />
}<br />
<br />
}<br />
<br />
....<br />
.....<br />
......<br />
<br />
}
Hop this helps
"It was the day before today.... I remember it like it was yesterday."
-Moleman
|
|
|
|
|
I did read the response
Console.Write("\b.") and tried it, it didnt work. I was getting the comma as well as well the full stop. But later I realised that "\b" stands for a backspace. So I tried
Console.Write("\b\b.") and it worked. It was a simple solution.Thanx buddy.
|
|
|
|
|
|
My boss told me I have to build Skynet by Monday...but I'm a BSA. Does anyone have any experience programming for neural net processors for the T-101? I think it uses .NET HELP HELP HELP!!! (hehehe) ....*sigh* and yes, I've searched Google!!
"I need build Skynet. Plz send code"
|
|
|
|
|
...I don't understand how this programming stuff is so hard!! I have an MCSD and 35 years Java experience!!
"I need build Skynet. Plz send code"
|
|
|
|
|
Aaaaah, so that's how it'll happen; someone in the future will find this post, write Skynet, and send it back to you... on a floppy.
|
|
|
|
|
seriously...I'm a BSA. I know all. ...Which is why I MUST have this power!!!
"I need build Skynet. Plz send code"
|
|
|
|
|
Alaric_ wrote: BSA
Boy Scouts of America?
The (defunct?) motorcycle manufacturer?
|
|
|
|
|
Officially: business systems analyst
Unofficially: Bull S**t Artist
(Basically, it's a job title that was made up for people that "slide" into IT from a non-technical department)
"I need build Skynet. Plz send code"
|
|
|
|
|
Hello again Kyle.
--
You have to explain to them [VB coders] what you mean by "typed". their first response is likely to be something like, "Of course my code is typed. Do you think i magically project it onto the screen with the power of my mind?" --- John Simmons / outlaw programmer
|
|
|
|