|
Thanks Tom,
1.
I read your VB code. It returns string other than returns int. What I want is to get int (32-bit output). Any comments?
2.
"Don't really have any code for it, it was just my first thought and what I would try to do first. (but if there only numeric values in the hash it's simple, if not you'll probably have to do a check if the byte is numeric or not if not you could use the Asci value of the char or something else)" -- I read it twice, but do not understand. It is appreciated if you could some pseudo code for this idea? Code makes everyone clear.
regards,
George
|
|
|
|
|
Well like I said it's a thought and I'm not sure you'll always get a unique value out off it but here is some pseudo code anyway.
'the hashed string
String Hash="1564897548846357815";
Char c ;
Int result;
for each c in hash
if isnumeric(c) then
result = result + c
else
'do something to convert the char into an int
end if
next
Now I seriously doubt that this will work (reading the comments off other reply's to your post), but it was my first thought and you never know.
It also depends on for what you'll use the int (if it has to be unique I wouldn't do it like this).
PS: sorry if my c# code isn't perfect, been a while since I coded in it ![Smile | :)](https://www.codeproject.com/script/Forums/Images/smiley_smile.gif)
|
|
|
|
|
George_George wrote: but result in the form of an int.
Why George ?
cheers,
Abhijit
CodeProject.Com MVP
|
|
|
|
|
Hi Abhijit,
It is legacy system interface limitation. It has to use 32-bit int. Any ideas to convert a string into 32-bit int? The best idea I could think of is to calculate hashing for the input string. But the hashing result is not 32-bit, so I am thinking about how to convert it...
Any comments or ideas?
regards,
George
|
|
|
|
|
Don't know if you've sorted this or not George but thought I'd throw in my 2c worth.
As you know MD5 is 128bit (16 bytes) so there's no way of getting a unique value into an Int32. The same applies to Int64.GetHashCode() method - if you test it, you'll find you will get identical results for different values as it's impossible to make 64 fit into 32.
There are 32 bit hash algorithms out there - if it's just for file checking etc then it will be good enough, but if it's for security then forget it. If it's just for the sake of turning an arbitary string into an int then use GetHashCode() on your string.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Thanks Dave,
I can not use GetHashCode because for different CLR versions, the same content will return different results.
I think if there could be a hashing algorithm which returns 32-bit result, it will be great! But I can not find a built-in one in CLR library. Do you know whether there is a built-in one?
regards,
George
|
|
|
|
|
Have a look at this[^]. Be sure to check out the very last coment on the page as it could be important.
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Perhapse this?
string a = "Input String";
MD5 crypto = MD5.Create();
byte[] rawHash = crypto.ComputeHash(UTF32Encoding.Default.GetBytes(a));
Guid guid = new Guid(rawHash);
int hash = guid.GetHashCode();
|
|
|
|
|
Hi Jon,
Sorry I can not use GetHashCode because different CLR version will return different result for GetHashCode for the same input content.
Any comments or other new ideas?
regards,
George
|
|
|
|
|
You can generate your own hash:
string a = "Input String";
MD5 crypto = MD5.Create();
byte[] rawHash = crypto.ComputeHash(UTF32Encoding.Default.GetBytes(a));
Guid guid = new Guid(rawHash);
int hash = 0;
for (int i=0; i<16; i+=4)
{
hash ^= (rawGuid[i] << 24) | (rawGuid[i+1] << 16) | (rawGuid[i+2] << 8) | rawGuid[i+3];
}
return hash;
|
|
|
|
|
See How to get MD5 hash in C# . NET[^].
Of one Essence is the human race
thus has Creation put the base
One Limb impacted is sufficient
For all Others to feel the Mace
(Saadi )
|
|
|
|
|
hello,
i have created a setup for my application that instance a database into sql server.
when adding some features to my project i have changed some tables and some columns in my database.
My problem is that: how to update the database in my setup without overwriting the existing database and also do not losing the data.
any help is appreciated.
regards
dghdfghdfghdfghdgh
|
|
|
|
|
Instead of installing a database during an upgrade setup you should create a script which adds/updated/removes the rows/columns/tables to datatabase.
|
|
|
|
|
Hi ellie,
you could try to use a sql-script that looks like this:
<br />
IF NOT EXISTS (SELECT COLUMN_NAME FROM syscolumns WHERE COLUMN_NAME = 'MyColumn') THEN<br />
ALTER TABLE ADD COLUMN MyColumn varchar(256) NULL;<br />
END IF<br />
You can use this style for tables, triggers, columns etc.
During your installation you can execute this script.
Hope this helps you.
Regards
Sebastian
P.S.: Be sure to modify the sql-code above to the grammar of your sql server.
|
|
|
|
|
Hi all,
I need to create an application thru coding which will pop up when a user trying to establish a connection with my mechine.
Is there any way to do this
Language : C#.net
Thanx
Nidheesh
|
|
|
|
|
Yes there is very easy way to do it
Step 1. Search on google.
Step 2. Start coding.
rahul
|
|
|
|
|
|
|
Hello all,
There is some C# 2005 component that I want to use from VB6.
C# DLL registered for COM interop.
If I run VB application as stand-alone all works fine.
If I want to debug an application from VB IDE I get an "automation error" on NEW with error code -2146233036(80131534).
All sagestions appreciated...
|
|
|
|
|
When you run in the IDE, your app's path is effectively c:\Program Files\Microsoft Visual Studio\VB98\VB6.EXE. This means it will search for the dll in the VB98 directory. Try placing your dll here. Or adding a environment variable "devpath" to point to the dlls location.
Simon
|
|
|
|
|
Simon, thank you for replay!
I have solved this issue exectly as you proposed: placed all referenced assemblies in VB6's directory.
But I don't understand why it looking for them there... I checked CurDir and in debug time it's a my application EXE directory, rather than VB's directory.
So, VB6.EXE loads my application exe; looks in registry for COM interop; loads a TLB from my application directory and ....? How it comes back to VB6's directory?
|
|
|
|
|
Check the App.Path rather than the CurDir. You'll find it's set to the VB98 directory.
Don't quote me on this, but my guess is you've got your order wrong. This is my guess at what is going on.
1) VB6 loads app exe.
2) Sees requirement for external assembly reference.
3) Searches App.Path location for required assembly.
4) Assembly found, and read, TLB required so check registry.
5) TLB location read from registry.
6) TLB loaded.
In .net you can use the Fusion log viewer[^] to monitor assembly bindings and searched locations as they are loaded. I don't know if it works when the assembly is being loaded by VB6 though.
Simon
|
|
|
|
|
and again thank you for fast replay !
and for VERY helpfull tool (yep, seems it's monitoring entire CLR activity, so an interop activity as well).
|
|
|
|
|
Hello everyone,
I am using xsd to generate a C# class from an XML file. I noticed there are a couple of fields of the generated classes are marked with various XML attribute, like XML attribute and XML element.
Now I want to add more restrictions to the input XML file during deserialization,
- Make some fields in the C# class not nullable during serialization;
- Make some fields to accept only numbers (currently the automatic generated C# file is using string type other than number type to represent the fields).
Any ideas about how to decorate the generated C# class file to achieve the goal?
thanks in advance,
George
|
|
|
|
|
Hello Forum
I am new for this concept.
I want to create a web site in Asp.Net using c#.Net in which user can create his mail account like in code project,yahoo or gmail etc...like
abc@gmai.com
Do i need my own server?or the domain space will be sufficient on any server?
Any Basic Technology required?
Can any bdy tell me some steps to follow in the creation of that Web site
My basic Confusion is how and where to store the Mails and their format...?
Thanx n Regards
Rahul
|
|
|
|