Skip to main content
Inspiring
Nov 15, 2018 9:06 PM UTC
Question

Count with A, B, C, D instead of 0, 1, 2, 3, ...

Essentially, I want to count with letters, like Microsoft Excel does, instead of numbers. So instead of printing "We are at 0", "We are at 1", "We are at 2", etc., I need to print "We are at A", "We are at B", "We are at C", etc...

This topic is closed to new replies. Start a new post to keep the conversation going.

8 replies

BarlaeDC
Community Expert
Community Expert
Nov 16, 2018 4:09 PM UTC

Hi,

Something like this.

var curLetterAsNumber = 65; // start with a

var bContinue = true;

while ( bContinue){

     var myDisplayString = "We are at " + String.fromCharCode ( curLetterAsNumber);

     console.println ( myDisplayString);

      curLetterAsNumber++;

      if ( curLetterAsNumber > 90)

     {

            bContinue = false;

     }

}

This code just loops and prints the text to the console, but should give you an idea of how to use it.

Regards

Malcolm

Translate
hackertomAuthor
Inspiring
Nov 28, 2018 9:45 AM UTC

Because i use greek  Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ Τ Υ Φ Χ Ψ Ω

and not English A B C... i try with ascii table 128 who's is A Greek 129 is B Greek but compiler returns me non character a black cycle dot...

Translate
try67
Community Expert
Community Expert
Nov 28, 2018 10:15 AM UTC

It would have been helpful if you said that from the beginning...

The code for GREEK CAPITAL LETTER ALPHA is 913.

Translate
hackertomAuthor
Inspiring
Nov 16, 2018 3:48 PM UTC

and how to count++ this?

Translate
try67
Community Expert
Community Expert
Nov 15, 2018 9:13 PM UTC

Each character has an ASCII code that you can use to do it. For example, "A" is 65, "B" is 66, etc.

You can convert a character to its code using the charCodeAt method of the String object, and a code to a character using String.fromCharCode(). For example:

"A".charCodeAt(0); //returns 65

String.fromCharCode(65); // returns "A"

So all you have to do is add 65 to your number and then convert it to a character to achieve what you described.

Translate
Thom Parker
Community Expert
Community Expert
Nov 15, 2018 9:24 PM UTC

Be sure to test for the limit so you don't go past "Z"

Translate
Thom Parker - Software Developer at PDFScriptingUse the Acrobat JavaScript Reference early and often