• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

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

Explorer ,
Nov 15, 2018 Nov 15, 2018

Copy link to clipboard

Copied

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

TOPICS
Acrobat SDK and JavaScript

Views

196

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 15, 2018 Nov 15, 2018

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 15, 2018 Nov 15, 2018

Copy link to clipboard

Copied

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

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 16, 2018 Nov 16, 2018

Copy link to clipboard

Copied

and how to count++ this?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 16, 2018 Nov 16, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Nov 28, 2018 Nov 28, 2018

Copy link to clipboard

Copied

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

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 28, 2018 Nov 28, 2018

Copy link to clipboard

Copied

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

The code for GREEK CAPITAL LETTER ALPHA is 913.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 28, 2018 Nov 28, 2018

Copy link to clipboard

Copied

Consider using an array or object to associate a number with the corresponding character. For the English alphabet from A-Z it would be:

var aLetters = ["", "A", "B", "C"];  // continue for the other letters

and you'd then do something like:

// Get the letter corresponding to the number 2

var sLetter = aLetters(2);  // Returns "B"

You'd just need to change the single character strings in the array to match what you want to use for each number. With JavaScript, you'd specify the capital Greek A string like this: "\u0391"

So you'd just need to get the unicode values for the other characters and do the same.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 28, 2018 Nov 28, 2018

Copy link to clipboard

Copied

LATEST

The codes are sequential. So "\u0391" (or 913) is indeed ALPHA, then "\u0392" (or 914) is BETA, etc.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines