|
Sent you a mail
|
|
|
|
|
You basically have two options:
1. Open the file as a textfile, but then you can only read it sequentially.
2. Open the file as a binary file, then you have to detect the line breaks yourself, and convert the bytes to text using the Encoding class, but you can read from any part of the file.
---
b { font-weight: normal; }
|
|
|
|
|
I dont quite get what you are saying here..
In this case it would be possible to read chunks from whereever you like in file...or did i dont understand what you saying?
<code>
FileStream fs=new FileStream(fileName, FileMode.Open, FileAccess.ReadWrite,
FileShare.None, 8192 ); //we use the default buffer
StringBuilder result=new StringBuilder(8192);
byte[] buffer=new byte[8192];
int count=fs.Read(buffer,0,8192); //reading a block from the file, here we could start for example on 2000 instead of pos 0 //(fs.Read(buffer,2000,8192))
ASCIIEncoding encoding=new ASCIIEncoding();
while (count!=0) //stop when Read returns 0
{
result.Append(encoding.GetString(buffer));
count=fs.Read(buffer,0,8192);
}
fs.Seek(0, SeekOrigin.Begin);
</code>
|
|
|
|
|
Yes, you can use the Seek method to go to any position in the file.
Note: There is an error in this comment in the code:
//reading a block from the file, here we could start for example on 2000 instead of pos 0 //(fs.Read(buffer,2000,8192))
Using that call would result in an error message. As the size of the array is 8192 bytes, you can't read 8192 bytes and put them in the array from index 2000. Between index 2000 and the end of the array there is only room for 6192 bytes.
---
b { font-weight: normal; }
|
|
|
|
|
You are so right, little mistake from my side
|
|
|
|
|
System.IO.File in .Net 2.0 is really fast and has some new methods like ReadAllText() and ReadAllLines(). Why not some custom methods for your app?
Later, JoeSox
"Football is a game of cliches, and I believe in every one of them." -Vincent Lombardi
CPMCv1.0 ↔ humanaiproject.org ↔ Last.fm
|
|
|
|
|
How do you mean you should do then?
|
|
|
|
|
I was thinking of using ReadAllText() within an asynchronous method. Just read chunks of the 80mb from a temp file using ReadAllText(), when the user nears the end point create, then read another chunk into the textbox.AppendText(tempfile.ReadAllText()).
Later, JoeSox
"Football is a game of cliches, and I believe in every one of them." -Vincent Lombardi
CPMCv1.0 ↔ humanaiproject.org ↔ Last.fm
|
|
|
|
|
ReadAllText() is synchronous method, when you try to read a large text file, your application will hang or slow down ... better to use asynchronous medthod !!!
|
|
|
|
|
hackerhcm wrote: ReadAllText() is synchronous method, when you try to read a large text file, your application will hang or slow down ... better to use asynchronous medthod !!!
Of course, I was thinking of using ReadAllText() within the asynchronous medthod. Just read chunks of the 80mb from a temp file or something using ReadAllText(), when the user nears the end point create then read another chunk.
Later, JoeSox
"Football is a game of cliches, and I believe in every one of them." -Vincent Lombardi
CPMCv1.0 ↔ humanaiproject.org ↔ Last.fm
|
|
|
|
|
How to get the real Length of UTF8 String?
Thanks
Nothing
-- modified at 11:58 Tuesday 7th March, 2006
|
|
|
|
|
String.Length?
___________________________________
Tozzi is right: Gaia is getting rid of us.
My Blog [ITA]
|
|
|
|
|
The length of an UTF8 string can be interpreted in two ways:
1. The number of bytes that the encoded data uses.
2. The number of character that the decoded data contains.
The Encoding class has the GetByteCount to calculate the first one, and GetCharCount to calculate the second one.
---
b { font-weight: normal; }
|
|
|
|
|
|
Hi. I'm trying to measure one line string with the space character at the end. For example "Testing string ".
The problem is that the size that I get is the same size measured without the space at the end. Anybody knows how to make MeasureString() take the space character at the end into consideration?
|
|
|
|
|
Make sure you pass StringFormat with MeasureTrainingSpaces:
StringFormat format = new StringFormat(StringFormatFlags.MeasureTrailingSpaces);
g.MeasureString(..., format);
|
|
|
|
|
Hi,
I need to desigen an OSK.
Does anybody know hoe do i keep the OSK out of focus even when i click it's buttons while keeping any other form (the target form) in focus so the cgharacters i'm sending from the OSK (Sendkyes) will reach thier destination?
tnx
--roy
|
|
|
|
|
I would imagine you'd send keyboard messages to the window in question.
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Use WS_EX_NOACTIVATE on the window styles, so the OSK won't gain any focus.
|
|
|
|
|
I've got some problems parsing strings and /* */ comments. Any help will be appreciated.
-----------------
// multyline comments
case '*': case '/': case '(': case ')': case '+': case '-': case '=': case '~': case '|': case ';': case '%': case '&': case '{': case '}': case ',': case '[': case ']': case '?': case ':': case '^': case '<': case '>': case '!': case '.':
substr += s[i];
i++;
{
if(i < s.Length && (substr == "/"))
{
if(i < s.Length && (s[i]== '*'))
{
do { substr += s[i];
i++;
}
while (i < s.Length && substr== "*/");
rTB2.Text += "Komentar - " + substr + "\n";
substr = "";
}
-----------------
case '"':
{
do
{
substr += s[i];
i++;
}
while (i < s.Length && s[i]!='"');
rTB2.Text += "Tekst - " + substr + "\n";
substr = "";
} brake;
-----------------
If someone want, here is a direct link to my code.
http://www.geocities.com/puma55555/MyC.zip
|
|
|
|
|
Why not just post your problem here? Few are going to take the time to download, unzip, and study your code on their spare time. Just post the problems you're havnig here and we can help you.
Also, if you code is in the C or C++ languages (guessing by your zip name), you're in the wrong forum.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Lent Revisited
The apostle Paul, modernly speaking
Judah Himango
|
|
|
|
|
|
I created a user control in C# that I'd like to display in IE. I also did create a virtual directory on my local host. It works fine on one machine, but I can't get the control to show up on 3 other machines. They just show a placeholder box for the control.
Here is html that I am using:
<object id="MyUserCtrl"
="" classid="http://localhost/MyCtrl/MyCtrl.dll#MyCtrl.UserControl1" height="500" width="500" viewastext="">
I think this might have something to do with my IIS settings?
Please help.
|
|
|
|
|
Do these other machines have the .NET Framework installed? They'll need it to run your control.
Also, is .NET Framework and IE security setup properly to allow code to be executed from a network source?
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
other machines do have .NET installed on them.
|
|
|
|