1、代码:
void MainWindow::on_pushButton_clicked() { QString str = "5"; QString str01 = str.leftJustified(3, ‘0‘); qDebug() << str01; str01 = str.rightJustified(5, ‘0‘); qDebug() << str01; str01 = str.rightJustified(2, ‘0‘); qDebug() << str01; }
2、控制台输出:
"500"
"00005"
"05"
3、
4、
5、