How to write a conditional statement acting as follows:
Probably at the beginning you need to check the number of characters
Dim array2() As String = array1.ToArray(GetType(String))
action.SetDynamicParameter("FileName", ((((((("%version%" + "_") _
+ String.Join(", ", array2)) _
+ "_") _
+ "%name%") _
+ ".jpg"))
I will be grateful for your help.
答案 0 :(得分:2)
在我看来,您只是想将数字填充为以零开头为3的长度的字符串。对吗?如果是这样,请尝试以下操作:
Private Function FormatMyName(ByVal Name As String) As String
Return Name.PadLeft(3, "0")
End Function
如果将其创建为函数,以便您更轻松地添加所需的其他格式(例如,添加.jpg扩展名)
答案 1 :(得分:1)
检查函数的返回值是否为零,或在将字符串传递给函数之前检查字符串的长度。
Private Function GetPaddedName(OriginalName As String) As String
Dim PaddedString As String = ""
Select Case OriginalName.Length
Case 1
PaddedString = "00" & OriginalName & ".jpg"
Case 2
PaddedString = "0" & OriginalName & ".jpg"
Case 3
PaddedString = OriginalName & ".jpg"
Case Else
PaddedString = Nothing
End Select
Return PaddedString
End Function