我正在尝试将VB6代码转换为C#并希望了解LSet和Mid,下面是我的vb6和C#代码,转换看起来很好
strPrint = ""
strPAD = Space(12)
LSet strPAD = Mid(Trim(rsVoucher.Fields("Reference")) & "", 1, 12)
strPrint = strPrint & strPAD & " " ' 13
string reference = vouchDr["REFERENCE"].ToString();
string temp_reference = reference;
if (reference.Length > 12)
{
temp_reference = reference.Substring(0, 12) + "";
}
strPAD = temp_reference + (new string(' ', 12 - temp_reference.Length));
strPrint = strPAD + " "; //13
答案 0 :(得分:0)
您正在寻找:' PadLeft'字符串对象的方法。
你的代码看起来像......
string temp_reference = reference.PadLeft(12, ' ');
if (temp_reference.Length > 12)
{
temp_reference = temp_reference.Substring(0, 12) + "";
}
temp_reference += " ";