字符串格式不起作用 [英] string format doesn't work

查看:119
本文介绍了字符串格式不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 我尝试使用字符串格式让数字在forloop中排成一行。



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


如果数字位数不同,则输出不对齐。


所以如果第一个 数字在 上游有4位数


,下一个有5位数


下游没有排队。



        谢谢

解决方案

你好Jordanhal,


>>

如果位数不同,则输出不对齐


根据我的理解,如果数字位数不同,你希望输出对齐吗?


请试试以下内容:


data2 = string.Format(" {0, -20} {1,-15} {2,-15}",dateFormated,upstream [4] .ToString(&quo t;#。00"),下游[5] .ToString("#。00"));


问候,


Judyzh


 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

解决方案

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


这篇关于字符串格式不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆