|
stancrm wrote: First you must change your "4e554c4c" into byte array.
And therein lies the issue, I need something quick - if you look at my modified first post I have added the hacky method I am using at the moment.
|
|
|
|
|
See my message again. I have added the function to change 4e554c4c to NULL.
I think that is the fastest way.
|
|
|
|
|
Thats great, considerably better than my loop and loop attempt
I have only made one amendment and that is to remove the trailing terminator:
public static string HexToString(string input)
{
input = input.Substring(0, input.Length - 2);
byte[] b = new byte[input.Length / 2];
for(int i = 0; i < input.Length; i+=2)
{
b[i / 2] = byte.Parse(input.Substring(i, 2), System.Globalization.NumberStyles.HexNumber);
}
return System.Text.Encoding.ASCII.GetString(b);
}
|
|
|
|
|
Here's my entry (no need to prepare the data as a byte array):
private static string HexToText(string hex)
{
string result = string.Empty;
for (Int32 i = 0; i < hex.Length; i += 2)
result += (char)byte.Parse(hex.Substring(i, 2), System.Globalization.NumberStyles.HexNumber);
return result;
}
Share and enjoy.
Sean
|
|
|
|
|
This is getting shorter and shorter
Anybody got a one liner?
Time to start doing some timings
|
|
|
|
|
Just remember, shorter may not necessarily mean faster. IMHO, you should perf test your alternatives before selecting one.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Sean Michael Murphy wrote: (char)byte.Parse(hex.Substring(i, 2), System.Globalization.NumberStyles.HexNumber)
Damn, I didn't know you could do that... I was doing it the hard way
public string DecryptHexString(string text) {
string output = string.Empty;
for (int i = 0; i < text.Length; i += 2) {
int hval = DeHex(text.Substring(i, 2));
int temp = (hval ^ (output.Length + 1) % 256);
output += (char)temp;
}
return output;
}
private int DeHex(string input) {
int val;
int result = 0;
for (int i = 0; i < input.Length; i++) {
string chunk = input.Substring(i, 1).ToUpper();
switch (chunk) {
case "A":
val = 10; break;
case "B":
val = 11; break;
case "C":
val = 12; break;
case "D":
val = 13; break;
case "E":
val = 14; break;
case "F":
val = 15; break;
default:
val = int.Parse(chunk); break;
}
if (i == 0) {
result += val * 16;
} else {
result += val;
}
}
return result;
}
Try code model generation tools at BoneSoft.com.
|
|
|
|
|
Does anyone know how to programmatically delete a previously created custom menu in Excel? I need to delete a menu on multiple machines and would really like to do this though a program. These menus were individually created directly in Excel. Thanks for you help in advance.
Jeremy
|
|
|
|
|
|
Hi,
Just wanted to ask if any body has worked on interactive services using .NET 2.0... MSDN says : "The creation of interactive services is not supported. To workaround this, you can create a non-interactive service and a separate control GUI application that communicates with the service using sockets or remoting.", on ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.NETDEVFX.v20.en/cpref11/html/T_System_ServiceProcess_ServiceType.htm.
If some body could help me regarding creation of interactive services, it will be great help...
Thanks in advance.
Regards.
|
|
|
|
|
What it is about "you can't do this" that's hard to understand?? MSDN already described the process I was going to suggest.
You create two applications, one being the service with no UI, and the other being the Windows Forms app that talks to the service app over Sockets or .NET Remoting.
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
Hello!
It seems I can´t use SendMessage with WM_GETTEXT either GetWindowText to retrieve a label´s caption =/
I read about it and most of the people used ReadMemory, but it´s too complicated! and reading the label´s caption is not my main goal.
Does anyone have suggestion?
Thanks!
|
|
|
|
|
Then what IS the main goal??
Dave Kreskowiak
Microsoft MVP - Visual Basic
|
|
|
|
|
I use a dll to click on popup windows and what I need to do is just read a caption, then I know what is being clicked!
|
|
|
|
|
Hi,
I want to create Custom Control just like MessageBox.
also want to add all the functionality of the MessageBox.
Plz help me out.
It's Urgent.
|
|
|
|
|
Messagebox is not a control , its a dialog window that is invoked by a static method.
you can create something similair by doing:
public static class MyMessageBox
{
public static MyOwnDialogResult Show(string title,string message,.whatever params you want.)
{
MyOwnMessageBoxForm form = new MyOwnMessageBoxForm ();
form.Text = title;
form.lblMessage.Text = message;
... setup icons etc.
form.ShowDialog();
MyOwnDialogResult result = form.GetMyOwnDialogResult;
return result;
}
}
this way you can make your own messagebox return the kind of result you want yourself.
it is also possible by doing a bit of win32 hacking to display the "real" messagebox and alter things in it.
but I dont see much reason to do so, its easier to roll your own and you can easier adapt it to your own needs.
//Roger
http://www.puzzleframework.com
|
|
|
|
|
|
|
How to use Commandwindow, Immediate to interact with code in a project.
Can use it in Runtime?
Jey
|
|
|
|
|
SysJey wrote: Can use it in Runtime?
Yes
SysJey wrote: How to use Commandwindow
Just start typing in commands
SysJey wrote: interact with code in a project
You can query values in the current scope by typing something like: "? this.Text" which will output the Text property of the current object. You can also set values in a similar manner. Just try typing stuff and see what happens.
The Welsh will always support two teams: The Welsh, and anyone playing England
|
|
|
|
|
Say I want the value of the xml element <name> whats the best/fastest way to retrive it?
Thanks
|
|
|
|
|
See this:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlXPathXPathNavigatorMethodsTopic.asp
|
|
|
|
|
Thanks but a totaly out of context link to umpteen methods doesn't really point me to the best/fastest way of retriving a single value from an XML file.
Any chance of being more specific?
What I'm after is a way of storing/reading a config file in XML rather than a txt file.
But i wont bother if every method is a lot more convaluted than doing a Readline() on a text file stream.
I was a nice simple way to read an xml value from a given element.
|
|
|
|
|
The easiest way it to use XmlSerialize Class.
Just give your instance to that class, then it will be automatically converted to Xml file.
Or just give the filename, then you can deserialize it, and you get an instance of your class.
|
|
|
|
|
The easiest way is with an XPath query, so if you have a simple document, say:
<Config>
<Name>MySetting</Name>
</Config>
you would load that into an XmlDocument instance using the Load or LoadXML methods, so:
XmlDocument xmlDoc = new XmlDocument();<br />
xmlDoc.Load("C:\myConfig.xml");
XmlNode nameTextNode = xmlDoc.DocumentElement.SelectSingleNode("Name/text()");
string name = nameTextNode.Value;
You can read any value from the xml document with the correct xpath query. XPath is quite a big subject, and takes some getting used to, but there is an Xml forum here for specific path questions.
Note that the above code was written quickly and is untested, it is just to illustrate the sequence... it may not compile but should give you an idea to start playing with.
---
How to get answers to your questions[^]
|
|
|
|