cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. EST on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

Discussions

Solve problems, and share tips and tricks with other JMP users.
%3CLINGO-SUB%20id%3D%22lingo-sub-482841%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%C2%BFExiste%20una%20funci%C3%B3n%20para%20convertir%20un%20car%C3%A1cter%20a%20su%20equivalente%20ASCII%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-482841%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3E%C2%BFHay%20una%20funci%C3%B3n%20para%20convertir%20un%20car%C3%A1cter%20a%20un%20n%C3%BAmero%20ascii%3F%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAl%20final%2C%20necesito%20traducir%20una%20columna%20basada%20en%20caracteres%20en%20datos%20a%20su%20equivalente%20num%C3%A9rico.Siempre%20resultan%20ser%20de%201%20o%202%20d%C3%ADgitos.Tan%20efectivamente%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%22A%22%20se%20convierte%20en%201%3C%2FP%3E%3CP%3E%22Z%22%20se%20convierte%20en%2026%3C%2FP%3E%3CP%3E%22AA%22%20se%20convierte%20en%2027%3C%2FP%3E%3CP%3E%22AB%22%20se%20convierte%20en%2028%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3Eetc.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EAs%C3%AD%20que%20di%20DIE_COLUMN%20%3D%20%22CA%22%20Quiero%20devolver%2079%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESe%20me%20ocurri%C3%B3%20la%20siguiente%20f%C3%B3rmula%20completamente%20fea%20...%20pero%20si%20hubiera%20una%20funci%C3%B3n%20char%20to%20ascii%2C%20podr%C3%ADa%20hacerlo%20mucho%20mejor.TIENE%20que%20haber%20una%20forma%20m%C3%A1s%20limpia.%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3EIf(%20Length(%20%3ADIE_COLUMN%20)%20%3D%3D%202%2C%0A%20Contains(%20%22ABCDEFGHIJKLMNOPQRSTUVWXYZ%22%2C%20Left(%20%3ADIE_COLUMN%2C%201%20)%20)%20*%2026%2C%0A%200%0A)%20%2B%20Contains(%20%22ABCDEFGHIJKLMNOPQRSTUVWXYZ%22%2C%20Right(%20%3ADIE_COLUMN%2C%201%20)%20)%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-482841%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CLINGO-LABEL%3Esecuencias%20de%20comandos%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-482894%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3ERe%3A%20%C2%BFExiste%20una%20funci%C3%B3n%20para%20convertir%20un%20car%C3%A1cter%20a%20su%20equivalente%20ASCII%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-482894%22%20slang%3D%22en-US%22%20mode%3D%22NONE%22%3E%3CP%3EPara%20la%20traducci%C3%B3n%20que%20est%C3%A1%20haciendo%2C%20su%20funci%C3%B3n%20funciona.Si%20se%20usara%20una%20funci%C3%B3n%20ASCII%20a%20Decimal%2C%20el%20car%C3%A1cter%20%22A%22%20devolver%C3%ADa%2065%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22txnelson_0-1651162823000.png%22%20style%3D%22width%3A%20824px%3B%22%3E%3Cspan%20class%3D%22lia-inline-image-display-wrapper%22%20image-alt%3D%22txnelson_0-1651162823000.png%22%20style%3D%22width%3A%20824px%3B%22%3E%3Cimg%20src%3D%22https%3A%2F%2Fcommunity.jmp.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F42099i4F51BA46F61A4E88%2Fimage-dimensions%2F824x542%3Fv%3Dv2%22%20width%3D%22824%22%20height%3D%22542%22%20role%3D%22button%22%20title%3D%22txnelson_0-1651162823000.png%22%20alt%3D%22txnelson_0-1651162823000.png%22%20%2F%3E%3C%2Fspan%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
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