Set Space for text

Asked

Viewed 52 times

3

Good afternoon, I would like to know if there is a cmd command to set a fixed space for the text so that it does not change the position of the rest of the sentence.

In the example below this space is the * ㅤ ㅤ ㅤ*

My name is * Carlos ㅤ ㅤ ㅤ*, here comes the rest of the sentence
My name is * João Vitor ㅤ ㅤ*, here comes the rest of the sentence
My name is * Alexssandra ㅤ *, here comes the rest of the sentence

1 answer

2

You can compose your string by concatenating the first two parts, adding the spaces, taking a substring and adding the end. See the example below.

@echo off
setlocal

set "espaco=                       "
set "prefixo=Meu nome é"
set "frase= ,aqui entra o resto da frase"

set "nome=Carlos"
set "linha1=%prefixo% %nome%%espaco%"
set "linha1=%linha1:~0,24% %frase%

set "nome=João Vitor"
set "linha2=%prefixo% %nome%%espaco%"
set "linha2=%linha2:~0,24% %frase%

set "nome=Alexssandra"
set "linha3=%prefixo% %nome%%espaco%"
set "linha3=%linha3:~0,24% %frase%

echo %linha1%  & echo %linha2%  & echo %linha3%

inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.