none
string format doesn't work

    Question

  •  i am try to use string format to get numbers to line up in a forloop.

    data2 = string.Format("{0,20}{1,15}{2,15}", dateFormated, upstream[x].ToString("#.00"), downstream[x].ToString("#.00"));

    if the number of digits is different the output does not line up.

    so if first  number in  upstream has 4 digits

    and the next has 5 digits

    downstream does not line up.

             thank you

    Wednesday, January 03, 2018 9:16 PM

All replies

  • Hi Jordanhal,

    >> if the number of digits is different the output does not line up

    Based on my understanding, you want the output to be align if the number of digits is different, right?

    Please have a try with following:

    data2 = string.Format("{0,-20}{1,-15}{2,-15}", dateFormated, upstream[4].ToString("#.00"), downstream[5].ToString("#.00"));

    Regards,

    Judyzh


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 04, 2018 5:09 AM
  • Use a proportional font for output (e.g. “Courier New”), or give details about further usage of these strings.

    By the way, you can also write:

       data2 = string.Format( "{0,-20}{1,15:#.00}{2,15:#.00}", dateFormated, upstream[x], downstream[x] );

    Thursday, January 04, 2018 6:06 AM
  • Hi Jordanhal,

    How is it going with the issue currently?

    Please feel free to tell us the latest situation, if any reply helped you to resolve your issue or doubts, please help us to mark it as answer then I will close this thread. If the issue still exists please post the latest result of it, we will try our best to help you out.

    Thanks for your understanding. 

    Regards,

    Judyzh


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, January 15, 2018 8:51 AM