簡體   English   中英

VB6到C#代碼LSet Mid

[英]VB6 to c# code LSet Mid

我試圖將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

您正在尋找:'PadLeft'字符串對象的方法。

您的代碼看起來像....

string temp_reference = reference.PadLeft(12, ' ');

if (temp_reference.Length > 12)
{
     temp_reference = temp_reference.Substring(0, 12) + "";
}

temp_reference += " ";

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM