|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Words to NumberHi 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 wrote:
> Say for instance, the word "Fred" the numerical value of that word is How about this?> "6+18+5+4 = 33" 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.
Show quote
Hide quote
"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-k> wrote in message Good example, the OP should know that "ABCDEFG1234" will return the same news:eat0bk$dv8$1@south.jnrs.ja.net... > Condeh wrote: > >> 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. 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 Show quoteHide quote "Mythran" wrote: > > "Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-k> wrote in message > news:eat0bk$dv8$1@south.jnrs.ja.net... > > Condeh wrote: > > > >> 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. > > Good example, the OP should know that "ABCDEFG1234" will return the same > value as "ABCDEFG" :D > > Mythran > > > Wow, thats spot on, thanks very much, I'll now try and mkae sense of it
all! Thanks again! Phill W. wrote: Show quoteHide quote > Condeh wrote: > > > 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.
1 Variable - 2 Forms
Co-existing ASP.NET 1.1 and 2.0??? Accessing Structure Members Communication between threads Transactions through Remoting Excel already runnig, how to update with VB Printing on a new page Detect TcpClient Connection dropped use of mouse scroll in my crystal report viewer How to change ConnectionString for DataSet at runtime? |
|||||||||||||||||||||||