Words to Number

  • Thread starter Thread starter Condeh
  • Start date Start date
C

Condeh

Hi There

Im looking to do something, although im not sure if its possible.

Say for instance, the word "Fred" the numerical value of that word is
"6+18+5+4 = 33"

Is there anything i can do to get a phrase such as "humpty dumpty sat
on the wall" converted into number, and then added together?

Thanks for any help!
 
Condeh said:
Say for instance, the word "Fred" the numerical value of that word is
"6+18+5+4 = 33"

How about this?

Function AddUp( ByVal sText As String ) As Integer

Const kSet As String = "abcdefghijklmnopqrstuvwxyz"
Dim iTotal As Integer = 0

For iSub As Integer = 0 To sText.Length - 1
Dim iPos As Integer _
= kSet.IndexOf( sText.SubString( iSub, 1 ).ToLower() )

If iPos > -1 Then
iTotal = iTotal + ( iPos + 1 )
End If
Next

Return iTotal
End Function

? AddUp( "Fred" )
33
? AddUp( "humpty dumpty sat on the wall" )
352

HTH,
Phill W.
 
Phill W. said:
How about this?

Function AddUp( ByVal sText As String ) As Integer

Const kSet As String = "abcdefghijklmnopqrstuvwxyz"
Dim iTotal As Integer = 0

For iSub As Integer = 0 To sText.Length - 1
Dim iPos As Integer _
= kSet.IndexOf( sText.SubString( iSub, 1 ).ToLower() )

If iPos > -1 Then
iTotal = iTotal + ( iPos + 1 )
End If
Next

Return iTotal
End Function

? AddUp( "Fred" )
33
? AddUp( "humpty dumpty sat on the wall" )
352

HTH,
Phill W.

Good example, the OP should know that "ABCDEFG1234" will return the same
value as "ABCDEFG" :D

Mythran
 
My question is: Does each letter or word have a value associated with it?

If so, a CaseSelect statement would work, wouldn't it? Assign a value for
each character/word and when that character or word is used create an
equation?

Michael
 
Wow, thats spot on, thanks very much, I'll now try and mkae sense of it
all!

Thanks again!
 
Back
Top