Files
Aer/tests/center_text.aer
T

27 lines
651 B
Plaintext

import 'math';
import 'console';
class Program {
private string center_text(string $word){
int $tot_width = 30;
char $symbol = '-';
int $middle = (int) Math::Round($tot_width/2);
int $length_word = strlen($word);
int $middle_word = (int) Math::Round($length_word / 2);
int $last_position = $middle + $middle_word;
int $number_of_spaces = $middle - $middle_word;
string $result = sprintf("%'{$symbol}{$last_position}s", $word);
for(int $i = 0; $i < $number_of_spaces; $i++) {
$result += "$symbol";
}
return $result;
}
public void main() {
string $str = 'Example text';
Console::Print($this->center_text($str));
}
}