Skip to main content
Inspiring
November 15, 2018
Question

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

  • November 15, 2018
  • 3 replies
  • 870 views

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 has been closed for replies.

3 replies

BarlaeDC
Community Expert
Community Expert
November 16, 2018

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

hackertomAuthor
Inspiring
November 28, 2018

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...

try67
Community Expert
Community Expert
November 28, 2018

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

The code for GREEK CAPITAL LETTER ALPHA is 913.

hackertomAuthor
Inspiring
November 16, 2018

and how to count++ this?

try67
Community Expert
Community Expert
November 15, 2018

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.

Thom Parker
Community Expert
Community Expert
November 15, 2018

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

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