String alignment
I want to align the string "Set" so it doesn't get affected by the length change in the parentheses. Doing {1,4} or {2,4} won't solve it because the right
parenthesis spoils it.
Console.WriteLine("A: ({0},{1}) Set {2} Health:{3,-3}", AX, AY, setA, hpA);
Console.WriteLine("B: ({0},{1}) Set {2} Health:{3,-3}", BX, BY, setB, hpB);
Console.WriteLine("C: ({0},{1}) Set {2} Health:{3,-3}", CX ,CY, setC, hpC);
PS - I want it to look like:
A: (-1,-5) Set 2 Health:80
B: (7,8) Set 1 Health:60 C: (-6,-4) Set 3 Health:100
B: (7,8) Set 1 Health:60 C: (-6,-4) Set 3 Health:100
11 Replies
What does it currently look like?
You can use string.PadLeft
A: (6,-3) Set 3 Health:80
B: (4,4) Set 1 Health:60
C: (-5,-9) Set 2 Health:100
i kinda wanna do it in one line of code
Not related but
Health:{3,-3}
can be just Health:{3}
I guess
I don't think you can fix your issue in a short way
You could preserve some space for the coords but that would result in a different output (more whitespace)adding "" as a new variable and using - can fix it but i wish there were a simpler way. it just doesnt feel right
you mean this
" "
? 🤔will try both now 🙂
it won't work - i think i have to align left all of this A: ({0},{1}) but cant do it
use tuples
and string interpolation
Ero#1111
REPL Result: Success
Console Output
Compile: 670.099ms | Execution: 39.289ms | React with ❌ to remove this embed.
thank you all edit: i was able to do it in one line. Console.WriteLine("A: {0,-7} Set {1,-2} Health:{2}", String.Format("({0},{1})", AX, AY), setA, hpA);
Console.WriteLine("B: {0,-7} Set {1,-2} Health:{2}", String.Format("({0},{1})", BX, BY), setB, hpB);
Console.WriteLine("C: {0,-7} Set {1,-2} Health:{2}", String.Format("({0},{1})", CX, CY), setC, hpC);
Nice! Yeah that's what I meant with reserving space 👍