C# 相当于 VB6 字符占位符 [英] C# equivalent of VB6 character placeholder
本文介绍了C# 相当于 VB6 字符占位符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有 C# 等价于 VB6 格式函数中使用的 @ 符号?
Is there a C# equivalent to the @ sign used in the VB6 format function?
VB6(@字符占位符)
显示一个字符或一个空格.如果字符串在格式字符串中出现@的位置有字符,则显示;否则,在该位置显示一个空格.占位符从右到左填充,除非有 !格式字符串中的字符.
VB6 (@ Character placeholder)
Display a character or a space. If the string has a character in the position where the @ appears in the format string, display it; otherwise, display a space in that position. Placeholders are filled from right to left unless there is an ! character in the format string.
推荐答案
我猜你的意思是使用 string.Format()
左对齐或右对齐.
I guess you mean left-justify or right-justify using string.Format()
.
在 C# 中是:
string s = string.Format("{0,-10}", 42);
// s = "42 "
string s = string.Format("{0,10}", 42);
// s = " 42"
这篇关于C# 相当于 VB6 字符占位符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文