AlessioForconi wrote: ↑Fri Mar 25, 2022 8:47 am
Salutations,
I would like to replace the letters of the alphabet with numbers.
A = 1 b = 2 c = 3 ...
I thought I was using an array instead of a switch, 26 possibilities are too many, to find out what the letter is and extract its number.
 
Besides the solutions given here, I can think of two others.
1
Code: Select all
on mouseUp
    answer convertprimary("E")
end mouseUp
function convertprimary pLetter
   return itemOffSet(toUpper(pLetter),"A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z")
end convertprimary 
Code: Select all
on mouseUp
    answer convertprimary("E")
end mouseUp
local sLetterArray
function convertprimary pLetter
   if sLetterArray is not an array then
      local c = 0
      repeat for each item i in "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z"
         add 1 to c
         put c into sLetterArray[i]
      end repeat
   end if
   
   return sLetterArray[ pLetter ]
end convertprimary 
The first version besides being more compact is faster  
 
---Edit---
What you have to do is call one of these two algorithms inside a loop.
Code: Select all
function LetterToNum pWord
   local tNexText
   repeat for each char tChar in pWord
      put convertprimary(tChar) after tNexText
   end repeat
   return tNexText
end LetterToNum