Problem 60232. Spreadsheet Column Number
Spreadsheet uses an alphabetic naming system for columns, starting with 'A', 'B', 'C', etc. The column names continue like 'AB', etc.
Given a string representing a column title in a spreadsheet, determine its corresponding column number. In spreadsheets, columns are labeled using a base-26 system with 'digits' A-Z, where 'A' represents 1 and 'Z' represents 26. Following this, two-letter columns start with 'AA' as 27 and continue until 'ZZ' as 702, and so forth.
Examples:
- column_number('A') returns 1: In a spreadsheet, the first column is labeled 'A', which corresponds to 1 in the numbering system.
- column_number('Z') returns 26: The last single-letter column in a spreadsheet is 'Z', which corresponds to 26.
- column_number('AB') returns 28: This represents a two-letter column. 'A' corresponds to 1 and 'B' corresponds to 2. So, it's 26 (A) + 2 (B) = 28.
- column_number('AZ') returns 52: 'A' corresponds to 1 and 'Z' corresponds to 26. So, it's 26 (A) + 26 (Z) = 52.
- column_number('BA') returns 53: The first letter 'B' corresponds to 2, and the second letter 'A' corresponds to 1. So, it's 26 * 2 (B) + 1 (A) = 53.
- column_number('BZ') returns 78: The first letter 'B' corresponds to 2, and the second letter 'Z' corresponds to 26. So, it's 26 * 2 (B) + 26 (Z) = 78.
- column_number('ZY') returns 701: The first letter 'Z' corresponds to 26, and the second letter 'Y' corresponds to 25. So, it's 26 * 26 (Z) + 25 (Y) = 701.
Solution Stats
Problem Comments
Solution Comments
Show commentsProblem Recent Solvers8
Suggested Problems
-
Make the vector [1 2 3 4 5 6 7 8 9 10]
50612 Solvers
-
Back to basics 20 - singleton dimensions
270 Solvers
-
517 Solvers
-
94 Solvers
-
There are 10 types of people in the world
1160 Solvers
More from this Author53
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!