I am trying to convert the VB6 code to C# and looking to understand LSet and Mid, below is my vb6 and C# code , does the conversion look fine
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
you are looking for: 'PadLeft' Method of string objects.
your code will look like ....
string temp_reference = reference.PadLeft(12, ' ');
if (temp_reference.Length > 12)
{
temp_reference = temp_reference.Substring(0, 12) + "";
}
temp_reference += " ";
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.