我试图一次向控制台和输出文件写入一行。我无法弄清楚如何填充字符串,以使字符串的左侧部分在不同的WriteLines和StreamWrite的之间相似地向左对齐,而右侧部分则向右对齐。
我尝试使用\ t,如果字符串的左侧部分的长度与其他字符串相似,则效果很好,但是如果字符串的长度差异太大,则失败。
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class='container'>
<nav>
<ul>
<li><a class="menutitle" onclick="hideMenu('#submenuId1')">Link</a></li>
<li><a class="menutitle" onclick="hideMenu('#submenuId2')">Link</a></li>
</ul>
</nav>
</div>
<div id="submenuId1" class="hiddenMenu">
<nav>
<ul>
<li>subMenuItem1</li>
</ul>
</nav>
</div>
<div id="submenuId2" class="hiddenMenu">
<nav>
<ul>
<li>subMenuItem1</li>
</ul>
</nav>
</div>
答案 0 :(得分:3)
您可以使用String.Format + {index,length}
Console.WriteLine(String.Format("{0,-10} {1,-20} ${2,-10} ${3,-10}", DateTime.Now, "Added Money", 10.00,10.00));
Console.WriteLine(String.Format("{0,-10} {1,-20} ${2,-10} ${3,-10}", DateTime.Now, "Cloud Popcorn A4", 10.00,6.35));
Console.WriteLine(String.Format("{0,-10} {1,-20} ${2,-10} ${3,-10}", DateTime.Now, "Cash Out", 6.35,0.00));