473,388 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Words to Number

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!

Aug 3 '06 #1
5 1147
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.
Aug 3 '06 #2
i think youl have to write your own function to do that
--
-iwdu15
Aug 3 '06 #3

"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-kwrote in message
news:ea**********@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
Aug 3 '06 #4
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

"Mythran" wrote:
>
"Phill W." <p-.-a-.-w-a-r-d@o-p-e-n-.-a-c-.-u-kwrote in message
news:ea**********@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
Aug 3 '06 #5
Wow, thats spot on, thanks very much, I'll now try and mkae sense of it
all!

Thanks again!
Phill W. wrote:
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.
Aug 4 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: superprad | last post by:
"X-No-Archive: yes" what I am looking for is 1. To create a list of different words of various lengths(1-15) using A-Z,a-z,0-9 and punctuations.Basically anything that could be found on a...
2
by: janet | last post by:
how can i count how many words have i written in a text area??? Like taking an example ... i am writing in this textarea of microsoft usergroup. and say in total i have written 50 words .. how...
8
by: DrNoose | last post by:
Hi! I'm writing a program that is supposed to read a line of input, count the words and the number of occurrences of each letter. Then it should prints the number of occurrences of each letter...
7
by: Sling | last post by:
I code in Rexx on the mainframe which has 2 built-in functions: word(s,i) & words(s). word(s,i) returns the ith word in the s(tring), and words(s) returns the number of words within the s(tring)....
6
by: Gary Wessle | last post by:
hi I have a data file with equal number of columns for each row. I need to get the number of rows and columns to allocate a matrix in gsl. getline (in, line) and parse the line for the number of...
3
by: Nhd | last post by:
I have a question which involves reading from cin and counting the number of words read until the end of file(eof). The question is as follows: Words are delimited by white spaces (blanks,...
7
by: Jay | last post by:
How would I be able to grab random words from an internet source. I'd like to grab a random word from a comprehensive internet dictionary. What would be the best source and the best way to go...
8
by: shapper | last post by:
Hello, I have a string which holds a text. Is it possible to create a substring which uses the first N words of that string? Thanks, Miguel
6
by: Xernoth | last post by:
Hi, I have an exercise that requests the following: Write a function that reads words from an input stream and stores them in a vector. Use that function both to write programs that count the...
2
by: alwaali | last post by:
Hi I need help please This is my project and i need a help to solve it with you A page of text is to be read and analyzed to determine number of occurrences and locations of different words. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.