Create Number from String

bortiquai

Member
Joined
Jul 5, 2007
Messages
17
Programming Experience
Beginner
How can you convert a string into a "Number", such that it always is the same result?

So, if you have the String: 142ST-12A, after "Converting" it you would end up with a number (all digits are 0-9)?

so my vision is:

Dim OrigStr as String = 142ST-12A
Dim NewNum as Long

NewNum = SomeConversionThing(OrigStr)

Thanks
 
Extract numeric digits from string

This will extract all numeric digits from a string and ignore all other characters. Input of string is in TextBox1; output in TextBox2:


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim message, ch As String, msg As String = ""
message = TextBox1.Text
For x As Integer = 1 To message.Length()
ch = message.Chars(x - 1)
If ch >= "0" And ch <= "9" Then
msg = msg & ch
End If
Next x
TextBox2.Text = msg
End Sub
 
Because the Original string may have non-numeric characters, and I don't want to remove them.

Basically, i am trying to create a unique "number" or ID. Using information that makes the id unique, i end up with an id that is very long - like more than 20 digits. I am trying to find a way to convert this into a string that is still unique, but much shorter - like 10 or so digits.

I have seen some code generators, or key generators that no mater what you enter, it gives you a string that is always x characters long, and the original string can be numbers, letters or non-alpha Numeric.

so that if you enter ABC123, you end up with an ID that is x characters long, and every time you enter ABC123 it is the same result. And if you enter 123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ!@#$%^&*() it is still only x characters long.

Also, the order of the character string would matter. so ABC123 would generate a different ID than 123ABC.

Any ideas on how to do this?
 
This is typically what hashing algorithms do, there are several functionalities for this in the .Net Framework. For example you can call GetHashCode method on a string.
 
Back
Top