Jump to content

Dúvidas em centrar um texto


BigMachine3

Recommended Posts

Bom dia!!

Estou com dúvidas em centrar um texto.

Eu queria que um certo texto e números fica-se da seguinte maneira, imaginando que o seguinte quadro é a tela da linha de comandos:

--------------------------------------------------------------------

I I

I I

I abcd 120.000 s I

I querty 160.000 s I

I pedro 0.000 s I

I ze 1000.000 s I

I antonieta 80.000 s I

I I

I I

I I

--------------------------------------------------------------------

Eu ainda só aprendi a usar o gotoxy mas neste caso não sei usá-lo.

Link to comment
Share on other sites

Para alinhar um texto para um total de len caracteres, tens os seguintes três métodos:

const foo = 'hello world';
     len = 20;

PadLeft(foo, len);    // alinha à esquerda
PadRight(foo, len);   // alinha à direita
PadCenter(foo, len);  // alinha ao centro

Para fazeres o que queres, é uma questão de "brincares" com eles 😉

Edited by thoga31

Knowledge is free!

Link to comment
Share on other sites

  • 4 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.