The line has changing values. Can vary from 1 to 4-digit. It is necessary to make it so that initially there was a place for these numbers and the line did not skip the whole while increasing the number of digits.

Conclusion now

1 остальное значение строки 1234 остальное значение строки(строка сдвинулась) 

Need to

  1 остальное значение строки 1234 остальное значение строки ( строка не сдвинулась) 

How to format a string in this way?

  • format where? for console output? - Grundy
  • The line is easy to modify. The numeric value in the ToString method. - Dmitrii
  • one
    String.Format("{0,4} {1}", 1, "остальное значение строки") - PetSerAl
  • 3
    padleft - Grundy

1 answer 1

To output text to the console, it is enough to set the width of the field:

 string s = "some text"; Console.WriteLine( "{0, 10} {1}", 1, s); Console.WriteLine( "{0, 10} {1}", 1234, s); 

Test

Similarly, you can format the string itself through string.Format .