简体   繁体   English

在 c# 上格式化来自 ReadExisting() 的缓冲区输入

[英]formating the buffer input from ReadExisting() on c#

i have a program where i read a list of values from an energy meter through a serial port.我有一个程序,可以通过串行端口从电表读取值列表。 to read the buffer i use the ReadExisting() method.要读取缓冲区,我使用 ReadExisting() 方法。 my problem is that the words in the second column have different length each raw so the list is not orginized well:我的问题是第二列中的单词每个原始长度不同,因此列表组织得不好:

在此处输入图片说明

i am looking for a way to make it look like this:我正在寻找一种方法来使它看起来像这样: 在此处输入图片说明

Thanks,谢谢,

Shay.谢伊。

You can use tab.您可以使用选项卡。 Like this:像这样:

Console.WriteLine($"value: \t{...} \t{...}");

\\t is a tabulator where it gives you the actual tab \\t 是一个制表符,它为您提供实际的制表符

or...或者...

Console.WriteLine("{0,10}{1,10}{2,10}{3,10}{4,10}",
  a[DisplayPos],
  b[DisplayPos],
  c[DisplayPos], 
  d,
  e);

where the first number inside the curly brackets is the index and the second is the alignment.其中大括号内的第一个数字是索引,第二个数字是对齐方式。 The sign of the second number indicates if the string should be left or right aligned.第二个数字的符号表示字符串应该左对齐还是右对齐。 Use negative numbers for left alignment.使用负数进行左对齐。

Or look at http://msdn.microsoft.com/en-us/library/aa331875(v=vs.71).aspx或查看http://msdn.microsoft.com/en-us/library/aa331875(v=vs.71).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM