19 lines
503 B
Rust
19 lines
503 B
Rust
|
pub fn convert_to_title(column: i32) -> String {
|
||
|
let radix = 26;
|
||
|
|
||
|
let mut column = column as u32;
|
||
|
let mut result = vec![];
|
||
|
|
||
|
while column != 0 {
|
||
|
// Subtract 1 so the number 0 would equal the value 1.
|
||
|
let value = (column - 1) % radix;
|
||
|
column = (column - 1) / radix;
|
||
|
|
||
|
// Add 65 so the modulo'd value will be in the 65 through 90 character range
|
||
|
// (upppercase letters).
|
||
|
result.push(char::from_u32(value + 65).unwrap());
|
||
|
}
|
||
|
|
||
|
result.into_iter().rev().collect::<String>()
|
||
|
}
|