Way to count the number of letters between 2 letters?

554
4
12-01-2020 01:40 PM
DougBrowning2
Occasional Contributor III

Is there a way to calc the numerical distance between 2 letters?  

In Python it would be ord("J") - ord("A") = 9

 

I made this on the wrong account but I can find no way to delete posts now?

Thanks

0 Kudos
4 Replies
IsmaelChivite
Esri Notable Contributor

Hi @DougBrowning2  I think this JS function will do: 

function returnDistance(a,b){ 
  return Number(a.charCodeAt(0))- Number(b.charCodeAt(0));
}

 

0 Kudos
DougBrowning2
Occasional Contributor III

I cannot use JavaScript since I work across multiple orgs.

thanks

0 Kudos
IsmaelChivite
Esri Notable Contributor

Hi Doug. I think in that case we are out of luck.

0 Kudos
DougBrowning2
Occasional Contributor III

Ended up doing it in Python after the fact.

arcpy.CalculateField_management(inTable, "SlopeReachLength", "(ord(!SlopeEndTransect!) - ord(!SlopeStartTransect!)) * !TransectSpacing!", "PYTHON_9.3")

thanks

0 Kudos