Programming Riddle: How might you translate an Excel column name to a number?

前端 未结 28 1412
[愿得一人]
[愿得一人] 2020-11-29 22:26

I was recently asked in a job interview to resolve a programming puzzle that I thought it would be interesting to share. It\'s about translating Excel column letters to actu

28条回答
  •  南笙
    南笙 (楼主)
    2020-11-29 23:00

    Another Delphi one:

    function ExcelColumnNumberToLetter(col: Integer): string;
    begin
      if (col <= 26) then begin
        Result := Chr(col + 64);
      end
      else begin
        col := col-1;
        Result := ExcelColumnNumberToLetter(col div 26) + ExcelColumnNumberToLetter((col mod 26) + 1);
      end;
    end;
    

提交回复
热议问题