Way to count the number of letters between 2 letters?

136
4
12-01-2020 01:40 PM
DougBrowning2
Occasional Contributor II

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 Frequent 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 II

I cannot use JavaScript since I work across multiple orgs.

thanks

0 Kudos
IsmaelChivite
Esri Frequent Contributor

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

0 Kudos
DougBrowning2
Occasional Contributor II

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