【发布时间】:2017-12-14 23:16:22
【问题描述】:
我下面的代码将文件名的某些部分分配给变量。这里重要的是变量“yearandmonth”,它是一个格式为“yyyy-mm”的字符串
Dim fileparts() As String
Dim delimiter As String = " - "
Dim company As String
Dim type As String
Dim bank As String
Dim bankaccount As String
Dim yearandmonth As String
Dim fileyear As String
Dim filemonth As String
fileparts = Split(localFileName, delimiter)
company = fileparts(0)
type = fileparts(1)
bank = fileparts(2)
bankaccount = fileparts(3)
yearandmonth = Left(fileparts(4), 7) ' RESULTS IN A STRING THAT WILL LOOK LIKE "yyyy-mm"
fileyear = Left(yearandmonth, 4) ' results in "yyyy"
filemonth = Right(yearandmonth, 2) ' results in "mm"
如何确保“yearandmonth”的输出是有效的年、月并且包含“-”?
【问题讨论】: