cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Don’t miss your chance to experience Discovery Summit Europe at our best available rate! Early bird registration through 31 Oct.
  • Image to Table JMP extension imports single or batch images as data tables. Useful to extract curves from pictures or convert image data to curve data to use in analyses like Functional Data Explorer. Download and install the extension.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar

Is there a function to convert a character to its ASCII equivalent?

Is there a function to conver a character to an ascii number?

 

In the end I need to translate a character based column in data into its numerical equivalent.  They always happen to be 1 or 2 digits.  So effectively 

 

"A" becomes 1

"Z" becomes 26

"AA" becomes 27

"AB" becomes 28

 

etc.

 

So say DIE_COLUMN = "CA"  I want to return 79

 

I've come up with the following thoroughly ugly formula... but if there was a char to ascii function I could do a lot better.   There HAS to be a cleaner way.

If( Length( :DIE_COLUMN ) == 2,
	Contains( "ABCDEFGHIJKLMNOPQRSTUVWXYZ", Left( :DIE_COLUMN, 1 ) ) * 26,
	0
) + Contains( "ABCDEFGHIJKLMNOPQRSTUVWXYZ", Right( :DIE_COLUMN, 1 ) )
3 REPLIES 3
txnelson
Super User

Re: Is there a function to convert a character to its ASCII equivalent?

For the translation you are doing, your function works.  If an ASCII to Decimal function was used, the character "A" would return 65 

txnelson_0-1651162823000.png

 

Jim
Craige_Hales
Super User

Re: Is there a function to convert a character to its ASCII equivalent?

Translating 2 character codes to a number is a good job for an associative array. You could create the aa with nested for loops. You might want to force lower case on the keys .
Craige
pmroz
Super User

Re: Is there a function to convert a character to its ASCII equivalent?

This will do it:

die_column = "CA";
If( Length( DIE_COLUMN ) == 2,
	(num(hex(Left( DIE_COLUMN, 1 ) )) - 40) * 26,
	0
) + num(hex(Right( DIE_COLUMN, 1 ) )) - 40

You would need to uppercase die_column.  This works because A is ASCII 41.

Recommended Articles