0

我有一个文本文件包含这样的:

03/02/2013 09:47:29 AM||User Name||Open||Normal||Path
03/02/2013 09:47:45 AM||User Name||Close||Normal||Path
03/02/2013 09:47:52 AM||User Name||Open||Normal||Path
03/02/2013 09:47:58 AM||User Name||Save||Normal||Path
03/02/2013 09:47:59 AM||User Name||Close||Normal||Path
03/02/2013 09:48:05 AM||User Name||Open||Normal||Path
03/02/2013 09:48:06 AM||User Name||Close||Normal||Path
03/02/2013 09:48:12 AM||User Name||Open||Normal||Path
03/02/2013 09:55:33 AM||User Name||Save||Normal||Path
03/02/2013 09:55:34 AM||User Name||Close||Normal||Path
03/02/2013 09:55:40 AM||User Name||Open||Normal||Path

当我从 Excel 中的 VBA 和 GetDay 中读取这一行时,将其拆分为分隔符“||” 天是“2”,但 2 是真正的月份。

我怎样才能得到这个日期,天是 3 月是 2?

4

1 回答 1

2

像下面的例子应该让你朝着正确的方向前进。

Dim row_string as String    'this is a row of text to be manipulated.

Dim sDay as String, sMonth as String, sYear as String
Dim sDateTime as String, sDate as String
Dim rowArr as Variant, elements as Variant, dateElements as Variant

'split the initial row into elements
rowArr = Split(row_string,"||")

'first element is the datetime string
sDateTime = rowArr(0)

'split the datetime string into individual parts
elements = Split(sDateTime," ")

'grab the date element
sDate = elements(0)

'split the date element up into parts
dateElements = Split(sDate,"/")


'Assign date elements to individual variables
sDay = dateElements(0)
sMonth = dateElements(1)
sYear = dateElements(2)


If sDay = "03" And sMonth = "02" Then

'do something here............

End If

或者我想你可以采用非常简单的方法并做..

Dim row_string as String

'check the left 5 characters of the entire string
If Left(row_string,5) = "03/02" Then

'do something here...........

End If
于 2013-02-24T11:34:08.427 回答