|
StreamReader sr = File.OpenText(pth);
str = sr.ReadToEnd();
byte[] m_abyData = new byte[str.Length];
int iPos = (0 / 3);
int iLen = (str.Length < (str.Length - iPos)) ? str.Length : (str.Length - iPos);
for (int i = 0; i < iLen; i++)
{
m_abyData[i] = (byte)str[i];
sbVar.Append(string.Format("{0:X2}", m_abyData[i]));
}
this is my actual code.
but it takes very long time for large file.(large in size).
e.g 70,000 kb it takes very long time.
give me solution for fast conversion.
|
|
|
|
|
Don't double post. People have already answered on your other thread[^]. You should post follow-up messages to that thread, not start a new one.
—In just two days, tomorrow will be yesterday.
—Hey, hey, hey. Don't be mean. We don't have to be mean because, remember, no matter where you go, there you are. - Buckaroo Banzai
[ Forum Guidelines] [ Articles] [ Blog]
|
|
|
|
|
Some ideas that might make your code work more efficiently.
piyush1230 wrote: str = sr.ReadToEnd();
So, you need to reserve a large block of memory to read the file. It is more efficient to read smaller chunks of the file, say a kilobyte or two, at a time.
piyush1230 wrote: m_abyData[i] = (byte)str[i];
You convert the string you have read form the file into a string, then convert it (badly) to binary again. Why not just read the file as a binary file in the first place? Then you won't have a double conversion. (i.e. .NET reads the file as binary then converts it to a string because that is what you asked for, then you convert it back to binary)
piyush1230 wrote: sbVar.Append(string.Format("{0:X2}", m_abyData[i]));
sbVar is not declared anywhere in the code you've provided so I'm guessing that it is a StringBuilder object. Do you need to build this in memory? Can it be written to a file as you go?
|
|
|
|
|
sbVar is StringBuilder.
I want solution for ( for loop ).
I want to eliminate for loop.
Plz. give me Instead of for loop any other function.
or give me code for using memory buffer ect. instead of array.
this code is for win ce mobile.
|
|
|
|
|
Hi,
two comments:
1.
a StringBuilder object acts like an array with some length (it's "Capacity").
When you append something and exceed the capacity, a new array is allocated and
all data is copied; this has a quadratic cost. It is better to allocate a
StringBuilder with sufficient initial capacity (twice the byte count of your file!).
I suggest you read up on StringBuilder documentation.
2.
I don't know what you intend to do with the entire hex stuff. Maybe you don't need
it all at once; if e.g. you want to write the data to another file, you can do the
read-convert-write process in chunks without ever needing a big array/string/StringBuilder
(and without wasting the memory).
|
|
|
|
|
|
Try reading up on how an ftp server works, the protocols, the standards, and then if you have a specific question about building an FTP server, post it up.
Just because we can; does not mean we should.
|
|
|
|
|
How can I get DateTime.now in this format: "Wed, 05 Apr 2006 21:12:00 GMT" ?
/\ |_ E X E GG
|
|
|
|
|
|
For instance, you can use:
string const MY_LONG_FORMAT = "MM/dd/yy HH:mm:ss:ffff"
string output = DateTime.Now(MY_LONG_FORMAT);
Note that the above format is NOT the one you want; you'll need to look at the link I provided in the earlier post to see how to build your format string.
modified on Friday, December 28, 2007 3:48:36 AM
|
|
|
|
|
string output = DateTime.Now.ToString("MM/dd/yy HH:mm:ss:ffff");
it will also work
Becoming Programmer...
|
|
|
|
|
Please only use ISO 8601 compliant formats.
|
|
|
|
|
|
hi
how to get motherboard and hard-disk serial number
in C# code ?
than'k alot for any help
|
|
|
|
|
|
There's an article on this site, I don't remember it, but a search should bring it up.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
|
I'm coding a program that the user can enter names in both arabic and english languages .. Can i program it to change the input language automatically ? usually the user have to press alt + shift to change the input language . i want the cursor to change to arabic when arabic names is need and to change to english else where ...
P.S
My english is bad . sorry
|
|
|
|
|
Thanks to everybody I've found the solution
using System.Globalization;
2)i decalre two CultureInfo one for the Deafult Language and the other to the second language (Arabic in my case)
CultureInfo arabic = new CultureInfo("ar-QA", false);
CultureInfo english = new CultureInfo("en-US", false);
2) in the focus enter event of the desired textbox i added the following code
private void txtName_Enter(object sender, EventArgs e)
{
InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(arabic);
}
so the language change to Arabic .
3) in the focus leave event of the same textbox i added
private void txtName_Leave(object sender, EventArgs e)
{
InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(english);
}
so the language returned to the default input language.
Thanks and i hope the explanation is enough.
Asaad Al Chalabi
abushalabi@hotmail.com
|
|
|
|
|
Cool deal finding the solution
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
Thank you very much for sharing this solution with us.
Best Regards
Tarik
|
|
|
|
|
Thanks.
I have been searching for a code snippet like that, because I wanted to have a Google Chrome plugin that indetifies the input field in focus, and changes the windows language.
e.g. switch automatically to Arabic when cursor is at "Name" field, and switch to English when cursor is at "Email" field.
Does anyone know how I can use this code in a Google Chrome plugin?
Does it support activating any windows native (binary) programs as part of plugins?
|
|
|
|
|
private void butDelete_Click(object sender, EventArgs e)
{
try
{
OleDbCommand deleteNode = new OleDbCommand("", dbProfiles);
{
//Check if the selectedNode is not root node.
//I have changed the code below to make the checkbox delete the child node and not the root node. Is //there anything else I need to add??
if (tvFavorites.SelectedNode.Tag == null && tvFavorites.SelectedNode.Checked == true)
{
if (MessageBox.Show("Do you want to delete the \"" + tvFavorites.SelectedNode.Text + "\" folder and all its files?", "Delete Folder", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
deleteNode.CommandText = "delete from favFiles where folder_id = " + tvFavorites.SelectedNode.Name;
if (dbProfiles.State == ConnectionState.Closed)
dbProfiles.Open();
deleteNode.ExecuteNonQuery();
deleteNode.CommandText = "delete from favFolders where folder_id = " + tvFavorites.SelectedNode.Name;
deleteNode.ExecuteNonQuery();
dbProfiles.Close();
tvFavorites.Nodes.Remove(tvFavorites.SelectedNode);
}
}
|
|
|
|
|
Hard to tell without having the rest.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
I want to print some things using a Mobile Pro Spectrum printer from an Optimus_PDA device. I work in c# .NET2005 please help me I want the correct dll I had Downloaded alot of them but it doesn't working .
So if some one help me by send me the correct dll or give ma an example I will be very thankful to him/her.
Bye Merry Christmas.
|
|
|
|