C# 如何在C中使用StrDup#
您好,我有一个用于VB.net的代码:C# 如何在C中使用StrDup#,c#,vb.net,C#,Vb.net,您好,我有一个用于VB.net的代码: Public Shared Function GetNextID(ByVal Prefix As String) As String Dim dt As DataTable = Database.GetDataTable("select * from _NumberGeneration Where Entity = '" & Prefix & "'") If dt Is Nothing OrElse dt.Rows.Coun
Public Shared Function GetNextID(ByVal Prefix As String) As String
Dim dt As DataTable = Database.GetDataTable("select * from _NumberGeneration Where Entity = '" & Prefix & "'")
If dt Is Nothing OrElse dt.Rows.Count = 0 Then Return ""
Dim format As String = dt.Rows(0)("Format") & ""
Dim sqlCnt As String = dt.Rows(0)("SQL") & ""
Dim cnt As Int32 = Val(Database.ExecuteScalar(sqlCnt)) + 1 ' 11
Dim RN As String = format.Substring(format.IndexOf("["c), 4) ' [R5]
Dim newRN As String = StrDup(CInt(RN.Substring(2,1), "0"c) ' 00000
newRN = cnt.ToString(newRN) ' String.Format(newRN, cnt) ' 00011
Dim newformat As String = format.Replace(RN, newRN) '"PR"yyMM00011
Return Today.ToString(newformat) ' String.Format(newformat, cnt)
End Function
对于我用C编写代码时的StrDup,与下面的代码相同:
string newRN=newstring(int.Parse(RN.Substring(2,1)),'0')
它显示错误。将字符串构造函数与字符和计数参数一起使用:
string newRN = new string('0', 4);
您也可以引用Microsoft.VisualBasic程序集并通过字符串模块调用该方法,但上面的替代方法非常简单。使用字符串构造函数和字符和计数参数:
string newRN = new string('0', 4);
您也可以引用Microsoft.VisualBasic程序集,并通过String模块调用该方法,但上面的替代方法非常简单