Solved

# Assigning letters a value

Posted on 2003-03-01
Medium Priority
156 Views
Hey all,
What I'm trying to do is break down a word and assign a value to each letter, so it needs to work with upper and lowercase just the same.  The values range from 1-9 and get assigned in order of the letters and when it reaches 9 it starts at 1 again (ie. A-1,B-2,I-9,J-1).  Then I need it to add the assigned values together.

Thanks.
0
Question by:Quantum
• 2

LVL 3

Expert Comment

ID: 8049588
wery easy   100% working solution
this assume that in string is only leters

s:='enyword';
rez:=0;
for j:=1 to length(s) do
rez:=rez+((ord[upcase(s[j])]-65) mod 9)+1;

this code if in word u mey have and other things like spaces numbers or enything else

s:='enyword';
rez:=0;
for j:=1 to length(s) do
if upcase(s[j]) in ['A'..'Z'] then
rez:=rez+((ord[upcase(s[j])]-65) mod 9)+1;

wery easy arent?

0

LVL 15

Accepted Solution

VGR earned 2000 total points
ID: 8051750
numerology ? :D

I have a lot of code...

Interface

Function Chiffrage(par:string):string;
Function Chiffre(par:char):byte;

Implementation

Function Chiffre;
Var chif : byte; { ATTENTION : ne s'appliquera qu'aux LETTRES. }

Begin
chif:=(Ord(UpCase(par))-64);
Case chif Of
1..9  : Chiffre:=chif;
10..18 : Chiffre:=(chif-9);
19..26 : Chiffre:=(chif-18);
End; { of CASE }
End;

Function Chiffrage;
Var lresult : string;
i      : byte;
ch     : string; { car bug de TPv4.0 : tjrs pas Char=st1 ! }

Begin
lresult:=par;
For i:=1 to Length(par) Do
Begin
Str(Chiffre(par[i]),ch);
lresult[i]:=ch[1];
End;
Chiffrage:=lresult;
End;
0

Expert Comment

ID: 9316991
Quantum:
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0

LVL 15

Expert Comment

ID: 9331691
split

or paq & norefund
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Is your organization moving toward a cloud and mobile-first environment? In this transition, your IT department will encounter many challenges, such as navigating how to: Deploy new applications and services to a growing team Accommodate employee…
###### Suggested Courses
Course of the Month8 days, 13 hours left to enroll