Convert a Letter Into a Number and Vice Versa

The title was because I had been testing some awk scripts I found online and when they didn’t work I just pasted this one in and didn’t update the title :laughing:

YES, I know why, You didn't follow my advice to ensure that the string starts and stops with a space. Try this text for input:

Got it! Working now, thanks for the help. Now I'm off to see if I can integrate it into my original macro haha.

Ok, great.

Got it integrated into my macro...

Ran some tests to compare how fast it executes vs my switch action and it's roughly the same speed....however the shell script is a lot simpler so I'm going to run them both for a few days and keep track of which one is more reliable/faster and go from there.

Thanks again for your help and patience!

You've been patient with me too, whenever I make you do a little work instead of just giving you all the answers. I think people should be allowed to give hints and tips instead of always giving out the full answer. It's not immoral to make people learn to help themselves.

  • Transferable – iOS scripting is no-go for AppleScript, and you can use JS in Custom HTML prompts, as well as the web generally.
  • Richer builtin libraries (Regex, array and string operations, uri encoding/unencoding etc)
  • Slightly stronger and easier built-in access to ObjC libraries

Those are probably the main things. If you use Omni apps they have moved their scripting model to JS, to allow the same scripts to run on iPad/iPhone as on macOS.

I agree actually. It helps folks like me learn the logic behind these things. Something, something, teach a man to fish haha! :laughing:

Good points all around. I'll set this aside for when I have some more time to look in JavaScript for some of my scripts. Thank you!

Hello:
If you are doing these conversions within your Numbers document, perhaps the built in functions would be sufficient.

Let there be two tables:
[1] "L2N" with the letters A-Z in column A. (In column B, the numbers 1-26 can be placed, but only initially to demonstrate that the formulas are working....)
[2] "Conversions". See image below:

Column A shows which conversion is sought.
Column B (Input) shows the input argument.
Column C (Output) the result.

The formulas in column C are:
For Number to Letter : INDIRECT("L2N::A"&FIXED(1+Input Number to Letter,0))
For Letter to Number : ROW(INDEX(Letters, MATCH(Input Letter to Number, Letters,0)))−1

Note: As can be seen in the formulas, Column B in L2N is not actually used as referring to the table row itself is sufficient.

Here's a scriptless way to do it with regex.

Letter/Number to Number/Letter Macro (v10.2)

Letter-Number to Number-Letter.kmmacros (2.5 KB)

2 Likes