سؤال

In this sequence:

aaa = 1
aab = 2
aac = 3
aad = 4
aae = 5
...

what is the easiest way to convert any other string in the sequence (up to max zzz) to a number, say aem, or svg as random examples?

Is there a spreadsheet formula to do this?

هل كانت مفيدة؟

المحلول

I'm not sure which language do you use. Because you mentioned spreadsheet I assume that it's something like Excel. In Excel the formula should look like this:

=(CODE(TEXT)-97)*26*26+
 (CODE(RIGHT(LEFT(TEXT,2),1))-97)*26+
 (CODE(RIGHT(LEFT(TEXT,3),1))-97) +
 1

The first line is responsible for the first letter, the second for the second letter and the third for the last letter. In the last line there is +1 because the result would be computed from 0 not 1.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top