Unanswered: convert a String of letters to an Integer number
Hello, I want some help.
I would like a program in C language by preference, how can convert a String of letters (or some words analyzed to letters) to an Integer number.
Each letter has a value based on the following formula: a=599, b=120, c=357, d=409, e=516, f=696,…,z=276
At the end of the conversion all the values of each letter must be added to a total (number).
For example the string : bad = 120 + 599 + 409 =
So is the total number.
Private Function StringToNumber(tmpString as String) as Integer
Dim tmpIndex as Integer
' clear results if no string
StringToNumber = 0
If Len(tmpString) < 1 Then
' Loop through string byte by byte
For tmpIndex = 1 to Len(tmpString)
StringToNumber = StringToNumber _
+ Asc(Ucase(Mid$(tmpString,tmpIndex,1))) - 64
64 is subtracted from the Ascii value of each byte "A" = 65 - 64 = 1,
"Z" = 90 - 64 = 26. This routine only works for letters. If you have punctuation or spaces, remove is from tmpString before calling this function.