Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: splitting words into numbers Post Reply Post New Topic
Author Message
jamesflowers
Newbie
Newbie
Avatar

Joined: 20 May 2009
Location: United Kingdom
Online Status: Offline
Posts: 1
Quote jamesflowers Replybullet Topic: splitting words into numbers
     Posted: 20 May 2009 at 1:44am
I have a string (in this instance 'James')
 
if a letter is assigned a number a=1 b=2 etc)
 
James equate to 48
 
How could I split all the constiuent letters out and add the sums ?
 
Thanks in advance
 
James(48)
 
-------------------------------------------------------
 
local stringvar word:='james'; //48
local numbervar wl:=length(word);
local stringvar x:=left(word,1);

numbervar let:=
if X ='a' then 1
else if X='b' then 2
else if X='c' then 3
else if X='d' then 4
else if X='e' then 5
else if X='f' then 6
else if X='g' then 7
else if X='h' then 8
else if X='i' then 9
else if X='j' then 10
else if X='k' then 11
else if X='l' then 12
else if X='m' then 13
else if X='n' then 14
else if X='o' then 15
else if X='p' then 16
else if X='q' then 17
else if X='r' then 18
else if X='s' then 19
else if X='t' then 20
else if X='u' then 21
else if X='v' then 22
else if X='w' then 23
else if X='x' then 24
else if X='y' then 25
else if X='z' then 26;

let

james.flowers@theclancygroup.co.uk
IFS reports Writer
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4374
Quote lockwelle Replybullet Posted: 20 May 2009 at 6:43am
I would loop through the letters and take the ascii value of the letter something like:
local numbervar counter;
local numbervar tot:=0;
local stringvar test:="james";
 
for counter = 1 to len(test)
  tot:=tot+asc(toupper(mid(test, counter,1)))-64;  //ascii A=65
next
 
tot
 
 
Now I may have the looping syntax wrong, look in help, but that is how I would do it.
IP IP Logged
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum